Absolute size of 'short'

Dennis Cohen drc at claris.UUCP
Wed Aug 3 00:24:44 AEST 1988


In article <214 at ISIDAPS5.UUCP> mike at ISIDAPS5.UUCP (Mike Maloney) writes:
>Is the size of a (signed or unsigned) short integer guarenteed to
>be two bytes?  I need to manipulate and compare some unsigned ints
>modulo 65536.  It would be clean and convenient to just let the
>machine handle my wrap-around from 0 to 0xffff and verse-vica.
>

Sorry, but the answer is "No".  As a matter of fact, it can't even be
guaranteed between compilers for the same piece of iron.  An example is the
Megamax C compiler for the Mac (and I think the Amiga as well) defines a
short to be 8 bits, an int to be 16, and a long is 32; the other four
compilers that I've used on the Mac define a short to be 16 bits.  The only
thing that is supposed to be guaranteed is:

	sizeof(short) <= sizeof(int) <= sizeof(long)

You might even find some where they're all the same size (I seem to recall a
compiler for CP/M which did that).

Dennis Cohen
Claris Corp.
------------
Disclaimer:  Any opinions expressed above are _MINE_!



More information about the Comp.lang.c mailing list