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

From ncm@zembu.com (Nathan Myers)
Subject Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Date
Msg-id 20010324164632.A1530@store.zembu.com
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
On Sat, Mar 24, 2001 at 02:05:05PM -0800, Ian Lance Taylor wrote:
> Tom Lane <tgl@sss.pgh.pa.us> writes:
> > 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 ...
> 
> True, for additional safety, do this:
>     ((((uint64) (unsigned long) 0xdeadbeef) << 32) |
>       (uint64) (unsigned long) 0xfeedface)

For the paranoid,
  ((((uint64) 0xdead) << 48) | (((uint64) 0xbeef) << 32) | \   (((uint64) 0xfeed) << 16) | ((uint64) 0xface))

Or, better
  #define FRAG64(bits,shift) (((uint64)(bits)) << (shift))  #define LITERAL64(a,b,c,d) \    FRAG64(a,48) | FRAG64(b,32)
|FRAG64(c,16) | FRAG64(d,0)  LITERAL64(0xdead,0xbeef,0xfeed,0xface)
 

That might be overkill for just a single literal...

Nathan Myers
ncm


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: gmake check fails on Solaris 8 with Sun cc
Next
From: Tatsuo Ishii
Date:
Subject: Re: 7.1 docs