Common ansi violation, exemplified.

Chris Torek chris at mimsy.UUCP
Thu Apr 21 12:33:39 AEST 1988


[various quotations of various people defining int_size_in_bits deleted,
but note that the original idea was to test the result in the preprocessor
proper]

In article <3323 at cg-atla.UUCP> duane at cg-atla.UUCP (Andrew Duane X5993) writes:
>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):

>#define NBBY    8               /* number of bits in a byte */
>#define NBPW    sizeof(int)     /* number of bytes in an integer */

[so]
>#define int_size_in_bits (NBBY*NBPW)

sizeof() is prohibited in preprocessor arithmetic; hence, with
this definition,

	#if int_size_in_bits <= 32

will not do anything useful.  The macro in <sys/param.h> is not a
violation of anything at all; use of the value produced by NBPW is
merely restricted to the compiler proper.  The Sun kernel has no
occurrences of the form `#if <expression involving NBPW>', and neither
can anyone else write this.  If you are content with doing this
arithemetic outside the preprocessor, there is no problem, but
somewhere back in the reference history, someone wanted to write

	#if int_size_in_bits <= 16
	typedef long foo_t;
	#else
	typedef int foo_t;
	#endif
	/* or something like that */
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list