From owner-freebsd-hackers Mon Apr 21 22:25:35 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id WAA15100 for hackers-outgoing; Mon, 21 Apr 1997 22:25:35 -0700 (PDT) Received: from post-ofc05.srv.cis.pitt.edu (post-ofc05.srv.cis.pitt.edu [136.142.185.10]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id WAA15092 for ; Mon, 21 Apr 1997 22:25:30 -0700 (PDT) Received: from morose.rmt.net.pitt.edu (ehdup-c2-9.rmt.net.pitt.edu [136.142.20.159]) by post-ofc05.srv.cis.pitt.edu with SMTP (8.8.5/cispo-2.0.1.7) ID for ; Tue, 22 Apr 1997 01:21:36 -0400 (EDT) Message-Id: <3.0.1.32.19970422012404.007b03f0@pop.pitt.edu> X-Sender: jddst19@pop.pitt.edu X-Mailer: Windows Eudora Light Version 3.0.1 (32) Date: Tue, 22 Apr 1997 01:24:04 -0400 To: freebsd-hackers@freebsd.org From: John Duncan Subject: Re: 64 bit number definitions? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 >> #include >> >> 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.