Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Дата
Msg-id 5905.985470194@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c  (Ian Lance Taylor <ian@airs.com>)
Список 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 по дате отправления:

Предыдущее
От: Ian Lance Taylor
Дата:
Сообщение: Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Следующее
От: Ian Lance Taylor
Дата:
Сообщение: Re: AW: AW: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c