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

How about ... (result >> 31) ? (result | (~0L << 32)) : result
The minimum number of bits in a `long' is 32 (LONG_MIN and LONG_MAX must be at most -2147483647 and +2147483647 respectively; the former allows for ones-complement). The result of a shift operator is defined if and only if the shift count does not equal or exceed the number of bits in the type. Thus, on a machine with 32-bit ints, `~0L << 32' is undefined. More practically, on (say) a VAX, the shift instruction only looks at the low 5 bits of the shift count, so ~0L << 32 will be ~0L => -1. Since there is now a new ugly set of `intNN_t' typedefs in <machine/types.h>, your best bet is probably: return (time_t)(int32_t)result; Chris

Since there is now a new ugly set of `intNN_t' typedefs in <machine/types.h>,
However, not all operating systems have such typedefs & I don't know of a standard that requires them. Probably a case for #ifdef'ing the code. - Tom
participants (2)
-
Chris Torek
-
Tom Peterson