Path: utzoo!attcan!uunet!pyrdc!ISIDAPS5!mike From: mike@ISIDAPS5.UUCP (Mike Maloney) Newsgroups: comp.lang.c Subject: Absolute size of 'short' Keywords: unsigned wrap-around Message-ID: <214@ISIDAPS5.UUCP> Date: 1 Aug 88 20:53:42 GMT Lines: 35 Dear C-Heavies, 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. The following works fine on my Xenix-386 machine, but is it portable? Note that the default integer size is 4 bytes, so the expression 'u' inside the printf's is being converted. unsigned short u; u = 0xffff; u++; printf("0x%x\n",u); ==> 0x0 u = 0; u--; printf("0x%x\n",u); ==> 0xffff Note however: u = 0xffff; u + 1 != 0 ==> In the expression 'u + 1', 'u' is upwardly converted to 4 bytes before adding 1. but (unsigned short)(u + 1) == 0 -- Mike Maloney "The nice thing about standards Integral Systems, Inc. is that there are so many to Lanham Maryland choose from" - Murphy