Of Standards and Inventions: A Cautionary Tale

Richard A. O'Keefe ok at quintus.UUCP
Tue Apr 12 16:23:59 AEST 1988


In article <10353 at steinmetz.ge.com>, davidsen at steinmetz.ge.com (William E. Davidsen Jr) writes:
> With programs traveling
> between 32 bit machines and 16 bit machines (286, 11s) I want to say:
> 	#if	sizeof int < 32
> 	#define INT	long
> 	#else
> 	#define INT	int
> 	#endif

I haven't got a copy of the latest dpANS (~ $70 in California).  For the
specific case of discerning the word-length of a machine known to be 2s-
complement, would
	#if (1<<1) < 0
	#define	int_size_in_bits	2
	...
	#elif (1<<15) < 0
	#define int_size_in_bits	16
	...
	#elif (1<<63) < 0
	#define int_size_in_bits	64
	#endif

	#if	int_size_in_bits < 32
	#define	INT long
	#else
	#define	INT int
	#endif
do the job, or may the preprocessor and compiler interpret int constants
differently?  Better yet, the dpANS provides a file <limits.h> which has
things like the size of various things in bits already defined in it.



More information about the Comp.lang.c mailing list