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

From: ncm(at)zembu(dot)com (Nathan Myers)
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: RELEASE STOPPER? nonportable int64 constant s in pg_crc.c
Date: 2001-03-25 00:46:32
Message-ID: 20010324164632.A1530@store.zembu.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Mar 24, 2001 at 02:05:05PM -0800, Ian Lance Taylor wrote:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> > Ian Lance Taylor <ian(at)airs(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2001-03-25 00:48:43 Re: 7.1 docs
Previous Message Tom Lane 2001-03-25 00:17:05 Re: gmake check fails on Solaris 8 with Sun cc