problem with detzcode on machines w/64 bit longs

Chris Torek torek at BSDI.COM
Fri Mar 10 19:38:59 UTC 1995


>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



More information about the tz mailing list