Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Apr 1997 01:24:04 -0400
From:      John Duncan <jddst19+@pitt.edu>
To:        freebsd-hackers@freebsd.org
Subject:   Re: 64 bit number definitions?
Message-ID:  <3.0.1.32.19970422012404.007b03f0@pop.pitt.edu>

next in thread | raw e-mail | index | archive | help
At 12:23 PM 4/22/97 +0800, you wrote:
>
>[snip]
>
>> 
>> I've recently (for a class) been forced to code under dos, so I think I 
>> know where your size guesses are coming from, but they're in error.  Run 
>> the following program:
>> 
>> #include <stdio.h>
>> #include <sys/types.h>
>> 
>> int main()
>> {
>>         int c;
>>         long l;
>>         quad_t q;
>> 
>>         printf( "sizeof int is %d, long %d, and quad %d\n",
>>                 sizeof( int ), sizeof( long ), sizeof( quad_t ) );
>> }
>> 
>> which has output "sizeof int is 4, long 4, and quad 8"
>
>Interesting... could it be due to alignment?
>
>Adrian.
>
>
>

int was never designed to be a specific number of bits, it just had to be
larger than two bytes. On some old machines, int was often 12 or 14 bits
long (one word... remember EBCDIC?) These days, the word size of our
"beloved" 386-class machines is 32. The word size of MIPS are 32. The word
size on an m68k is 16... But to maintain simplicity of transition for
programmers, and to keep old code running, intel calls the "word" the
16-bit long area, and the dword the 32. (With mmx, they babble of quadwords.)

Since there is a plethora of machines with 32-bit word sizes, I believe
that posix requires int to be 32-bits. It is on m68k unixes, at least. 

I think many c compilers that want to be portable on other platforms also
conform to this length. If you want size-specific types, use them instead
of int. The K&R manual (The C Programming Language, First edition, Eighth
printing, 1978):

	DEC PDP 11	Honeywell 6000	IBM 370	Interdata 8/32
char	   8 bits	    9 bits		 8 bits	   8 bits
int	  16		   36			32		  32
short	  16		   36			16		  16
long	  32		   36			32		  32
float	  32		   36			32		  32
double	  64		   72			64		  64

Standardizing the more meaningless types is kind of a pain for the future.
"If you have to rely on size, don't use them" is the message. If QIC says
that all offsets are to be calculated by a 321-bit number, or something,
then define the QIC_off_t to be 321 bits. It's as easy as that, I think.
Ada does a similar schtick, except it is spelled out "do not rely on the
types to be identical unless they are supposed to be identical."

-John


If you ever see an ambulance with sirens blaring and
twin 50mm cannons on top, do not interpret this as a
Good Sign. Be very, very frightened, in fact.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.1.32.19970422012404.007b03f0>