Absolute size of 'short'

Karl Heuer karl at haddock.ima.isc.com
Sat Sep 3 06:36:17 AEST 1988


People have suggested that some notation like `int:9 foo' should exist, which
declaration would reserve two bytes on a Vax, but only one on a Honeywell.

I will again point out that it is already possible to do this within the
current language, via a header file "ints.h".  On a PDP-11, it would contain:
	typedef char  int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8;
	typedef short int_9, int_10, /*...*/, int_16;
	typedef long  int_17, /*...*/, int_32;
	typedef unsigned char  uint_1, /*...*/, uint_8;
	typedef unsigned short uint_9, /*...*/, uint_16;
	typedef unsigned long  uint_17, /*...*/, uint_32;

Using the constants in ANSI C's <limits.h>, one could even write a universal
implementation of "ints.h" which is portable to all machines (given an upper
limit on the number of bits being supported).

(One admitted flaw: the bitwidth must be specified directly in this scheme;
you can't compute it at compile-time.)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list