tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: 64-bit masks



On Fri, 27 Nov 2009 14:16:23 -0000, der Mouse <mouse%rodents-montreal.org@localhost> wrote:

1. What is the correct (portable?) way of specifying 64-bit constants?

If I need a 64-bit constant set to all 1s, will the following work on
all systems

unit64_t num = 0xffffffffffffffffULL;

(Well, uint64_t.)  This will work on anything NetBSD runs on.  I'm not
sure whether unsigned long long is guaranteed by C to be at least 64
bits wide.  (Those versions of C that _have_ unsigned long long, that
is; it's a relatively recent addition to the language.)

You might want to write ~0ULL instead; it's smaller and somewhat
clearer.  (Just looking at what you wrote, I have to count characters
to tell you didn't write 0xfffffffffffffffULL instead, for example.)

Oh yeah, one's complement is much easier on the eyes. Thanks.


Home | Main Index | Thread Index | Old Index