www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/06/19:35:34

Date: Thu, 6 Oct 94 16:31:03 GMT
From: dolan AT fnoc DOT navy DOT mil (Kent Dolan)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: djgpp and the 386SX

> From: mcastle AT umr DOT edu (Mike Castle)

> In standard C, sizeof(short)<=sizeof(int)<=sizeof(long)
> In ANSI C, short>=16bits, int>=16bits, long>=32bits.

> Conceivably all three can be 64bits if the implementation so
> desires.

If I understood correctly passing remarks from my coworkers here who
program the Cray C90, a short int is 64 bits on that machine, because
it can add two 64 bit quantities faster than it can mask and shift, or
whatever, to get 16 or 32 bit quantities.  It also does 128 bit integer
arithmetic, so a long int may be 128 bits, or the compiler writers may
have implemented a long long int, I don't know -- in a shop with two
Crays and a Connection Machine, and a gaggle of Suns and other
workstations, I earn my living programming Intel/MS-DOS.

The general solution to the problem being discussed used by those who
program for portability is to have a "portability.h" that declares
macros INT8, INT16,INT32, INT64, or whatever, to match the appropriate
short, int, long, etc. declarations for the particular hardware, and
then use only the macros in routine bodies, thereby declaring the
expected size of the datum, rather than using the unpredictable size of
the standard C names for integers.  This puts the stuff that needs to
be changed all in one place, and makes the programmer's ambitions for
the number of bits in an integer-class variable explicit rather than a
matter of reverse engineering the code.

In C++, of course, this can be followed on with overrides of the
arithmetic operators to handle the unusually long integer types with
more complex, multiword operations where INT128, for example, is used
in the code but does not exist as a machine hardware data type.  Again,
this localizes the work of porting.

This is mostly folklore, and mostly off the topic, I have a low
resistance to the lure of typing for others to read.  Sigh.

Xanthian.
--
Kent, the man from xanth.
Kent Paul Dolan, CSC contractor at Fleet Numerical.  (408) 656-4363.
(Navy Unix email:   )  (Navy cc:Mail email: )  (real world email:     )
<dolan AT fnoc DOT navy DOT mil>  <dolank AT fnoc DOT navy DOT mil>  <xanthian AT well DOT sf DOT ca DOT us>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019