Re: problem with detzcode on machines w/64 bit longs

However, not all operating systems have [int32_t] ... Probably a case for #ifdef'ing the code.
Hm, good point, I was thinking of BSD systems specifically. (It is these `soma' muscle relaxant pills! I swear! :-) ) If one is to resort to #ifdef's, the original suggestion of testing the top bit and OR'ing in ~0L << 32 should work, using something like: #if LONG_MAX > 2147483647 /* long > 32 bits */ if (result & (1L << 31)) result |= ~0L << 32; #endif return (result); The (long)(int32_t) method may produce better code on an Alpha, Chris

Date: Fri, 10 Mar 1995 13:00:53 -0700 From: Chris Torek <torek@BSDI.COM> Message-ID: <199503102000.NAA17819@BSDI.COM> If one is to resort to #ifdef's, the original suggestion of testing the top bit and OR'ing in ~0L << 32 should work, using something like: Gawd - Chris, really, wouldn't just ... result = codep[0] & 0x80 ? ~0L : 0L; for (i = 0; i < 4; ++i) result = (result << 8) | (codep[i] & 0xff); return result; work rather more easily, without ifdefs, without caring whether char's are signed or not, without caring what is the size of a long (though since four 8 bit values are being packed in it had better be at least 32 bits), and without caring just what weird specific length casts the compiler might have, nor whether it compiles correct code for conversings involving such things (which some I have seen don't), etc... It is assuming that chars are 8 bits, or more correctly, at least 8 bits (which was assumed there before as well). kre
participants (2)
-
Chris Torek
-
Robert Elz