Common ansi violation, exemplified.

Andrew Duane X5993 duane at cg-atla.UUCP
Wed Apr 20 22:45:11 AEST 1988


In article <122 at gannet.cl.cam.ac.uk>, am at jenny (Alan Mycroft) writes:
> In article <1988Apr13.163235.420 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
> >> 	#elif (1<<63) < 0
> >> 	#define int_size_in_bits	64
> >Furthermore, even
> >ignoring that, there is another problem:  the result of shifting ***beyond***
> >the available number of bits is implementation-defined (or undefined).
> There is a related problem in lesser shifts in that the ANSI draft forbids
>         1<<31   even when ints have 32 bits (overflow)
> Note that
> 	1U<<31  has to be used instead.

Pardon me for coming in late, but hasn't anyone looked through
the system include files? In /usr/include/sys/param.h, I see
the defines (on a SUN3):

/*
 * Fundamental constants of the implementation.
 */
#define NBBY    8               /* number of bits in a byte */
#define NBPW    sizeof(int)     /* number of bytes in an integer */

If what you are after is a define for the number of bytes in an
integer, why not try:

#define int_size_in_bits (NBBY*NBPW)

Andrew L. Duane (JOT-7)  w:(617)-658-5600 X5993  h:(603)-434-7934
Compugraphic Corp.			 decvax!cg-atla!duane
200 Ballardvale St.		       ulowell/ \laidback
Wilmington, Mass. 01887		   cbosgd!ima/   \cgeuro
Mail Stop 200II-3-5S		     ism780c/     \wizvax

Only my cat shares my opinions, and she doesn't care how many
bits are in a byte, just how many bits are in her food dish.



More information about the Comp.lang.c mailing list