Absolute size of 'short'
Henry Spencer
henry at utzoo.uucp
Wed Aug 3 09:41:17 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?
No.
>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.
For unsigned numbers this would work, *if* you can find an unsigned size
that is two bytes long. There are no guarantees at all about that. (For
example, I believe there's a C compiler for the pdp10, and shorts would
pretty well have to be either 18 or 36 bits there. What they are on a
64-bit machine like a Cray, I have no idea, but I wouldn't count on them
being 16.)
I think the most portable way is to use (perhaps unsigned) long and do an
"&0xffff" at strategic places.
--
MSDOS is not dead, it just | Henry Spencer at U of Toronto Zoology
smells that way. | uunet!mnetor!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list