Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c - Mailing list pgsql-hackers

From Tom Lane
Subject Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Date
Msg-id 5905.985470194@sss.pgh.pa.us
Whole thread Raw
In response to Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c  (Ian Lance Taylor <ian@airs.com>)
List pgsql-hackers
Ian Lance Taylor <ian@airs.com> writes:
> A safe way to construct a long long constant is to do it using an
> expression:
>     ((((uint64) 0xdeadbeef) << 32) | (uint64) 0xfeedface)
> It's awkward, obviously, but it works with any compiler.

An interesting example.  That will work as intended if and only if the
compiler regards 0xfeedface as unsigned --- if the constant is initially
treated as a signed int, then extension to 64 bits will propagate the
wrong bit value into the high-order bits.

Indeed, according to the ANSI C spec, 0xfeedface *should* be regarded as
unsigned in a machine whose ints are 32 bits.  However, this conclusion
comes from the exact same paragraph that AIX got wrong to begin with.
I'm not sure that doing it this way actually affords any extra protection
against compilers that can't be trusted to handle integral constants
per-spec...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Ian Lance Taylor
Date:
Subject: Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Next
From: Ian Lance Taylor
Date:
Subject: Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c