32 bit longs

Lars Wirzenius wirzenius at cc.helsinki.fi
Fri Jan 25 11:25:22 AEST 1991


In article <1991Jan22.022206.24691 at tkou02.enet.dec.com>, diamond at jit345.swstokyo.dec.com (Norman Diamond) writes:
> In article <231 at nazgul.UUCP> bright at nazgul.UUCP (Walter Bright) writes:
>>
>>If you have a need for *exactly* 32 bits, you can do things like:
>>	if (sizeof(x) == 4)
>>		/* code here depends on 32 bits in x */
> 
> On a machine with 36-bit words and C support hacked with 9-bit chars,
> this test will give an undesired result.

Wouldn't the following work (assuming CHAR_BIT is defined properly), if
the aim is to verify that x has a size of 32 bits:

	if (sizeof(x) * CHAR_BIT == 32)

By the way, is there any guarantee that all bits are used to represent a
value? That is, does a 16-bit unsiged always have a value range of
0..65535?

Lars Wirzenius    wirzenius at cc.helsinki.fi



More information about the Comp.lang.c mailing list