Data Type Width Specifiers

Thomas M. Breuel uunet!ai.mit.edu!tmb
Fri Dec 20 12:10:46 PST 1991


Patrick Powell writes:
 > At the risk of throwing gasoline on the fire,  I wonder if it is
 > time to resurrect an old idea from FORTRAN and/or ADA,  that of adding a
 > data type width specifier to the language.  The idea would be
 > to specify the width (in bytes) of the data type.
 > This would apply to basic data types such as integer,
 > float, and perhaps could be extended to other data types.
 > 
 > For example (I know the syntax is ugly):
 > 
 > int<4>  ==  int         sizeof( int<4> ) == 4
 > int<8>  ==  long        sizeof( int<8> ) == 8
 > int<16> ==? long long   sizeof( int<16> ) == 16

Why does everybody want this fine control over integer sizes? Sure, it
looks neat on paper, but do you really _need_ it?  All I ever seem to
need (and rarely at that) is types that hold some minimum range.

 > The rules for width interpretation would have to be carefully
 > thought out.  For example,  what should happen if somebody specifies
 > a width that is not 'natural' for a specific machine?  How would
 > calculations be performed?  ADA has this problem... and solves
 > it by some very carefully detailed semantics.

I remain unconvinced that Ada "solves" this problem. Ultimately, the
tradeoffs between storage and speed involved in choices of particular
integral data types are application, machine, and implementation
specific; a compiler cannot even make a near-optimal choice without
programmer assistance. That's why the "blessed" way of handling this
is through writing your code in terms of typedefs that are then tuned
for each particular implementation.

As I said before, I think NCEG may want to recommend adoption of a
standard header file containing typedefs for commonly useful sizes,
i.e., containing entries like:

	/* integral type which has at least the range of a
	   32 bit signed 2's complement number */

	typedef int int32; /* For the Moon 3 machine */

This would let you write "generic" or "portable" versions of your
code, but for optimum performance and flexibility, you should still
express your algorithms in terms of typedefs.

					Thomas.




More information about the Numeric-interest mailing list