www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/03/03:49:16

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199605030716.AA173137813@relay1.geis.com>
Date: Fri, 3 May 96 07:25:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: sizeof(int) == 4?!

Reply to message 1204146    from MAX AT ALCYONE DOT C on 04/29/96 10:55AM


>There is nothing to correct, because nothing is wrong.  ANSI C does not put
>limitations on the sizes of types other than that sizeof char <= sizeof short
><= sizeof int <= sizeof long.  (Actually, there _are_ actually some further
>limitations, but they don't go to the level of specifying the byte-width of
>these types.)

Close, but not quite.  ANSI C does in fact specify the following conditions
for type sizes:

sizeof short >= 2 bytes (-32767 to +32767)
sizeof long >= 4 bytes (-2147483647 to +2147483647)
sizeof short <= sizeof int <= sizeof long
sizeof char == large enough to store the basic character set for the system
unsigned <type> == same size as signed <type>

sizeof float >= 4 bytes (or 6 significant digits)
sizeof double >= sizeof float (but must store 10 significant digits)
sizeof long double >= sizeof double

So the only thing that is any different between a 16- and 32-bit compiler is
the
sizeof int, which can be either 2 or 4 bytes.  Actually, pointers can also be
either 2 or 4 bytes, but they are usually the same as the int size.  Floating
point sizes vary arbitrarily by compiler.

Lest ye doubt my words, I am quoting directly from The Waite Group's _New
C Primer Plus_, 2nd edition.  :)

John

- Raw text -


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