[comp.lang.c] Portable integer types

drw@cullvax.UUCP (Dale Worley) (04/16/87)

Under the new ANSI standard, if you want to, say, define a type
'int12' that has at least 12 bits (signed), you can write:

#include <limits.h>
#if CHAR_MAX >= 2047
typedef signed char int12;
#elif SHRT_MAX >= 2047
typedef signed short int12;
#elif INT_MAX >= 2047
typedef signed int int12;
#elif LONG_MAX >= 2047
typedef signed long int12;
#else
#error No integer type wide enough for 12 bits!
#endif

And it's portable!

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw@eddie.mit.edu
Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)