TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: All
from: Bob Stout
date: 2003-11-16 19:21:48
subject: Re: [C] word sizes

From: Bob Stout 

On Sun, 16 Nov 2003, Jerry Coffin wrote:

> > To the question at hand... Referring to ISO/IEC 9899:1999, "5.2.4.2.1
> > Sizes of integer types ", the only
hard-wired type is char
> > (signed or unsigned), for which CHAR_BIT is defined as 8.
>
> I suspect you started out saying something accurate, and then tried to
> edit it down to size, and ended up with something that wasn't quite
> accurate anymore.

Guilty as charged. In my own defense, though, I've never heard of a
compiler where char wasn't 8 bits. The need for anything larger, given the
nature of the char type, is obviated by the existence of wchar_t. I have,
OTOH, heard of a couple of architectures where you couldn't necessarily
count on shorts being 16 bits or longs being 32 bits. Ints, of course, are
all over the map. Fortunately, the days of those architectures are, like
the days of one's complement math, mostly history.

> It is true that sizeof(char) is hardwired at 1.  CHAR_BIT, however, is a
> minimum of 8, but can be larger -- in the last sentence of paragraph 1
> of 4.2.4.2.1, it talks about CHAR_BIT and the other values in limits.h,
> saying:  "Their implementation-defined values shall be equal or greater
> in magnitude (absolute value) to those shown, with the same sign."
> IOW, if an implementation chose to use CHAR_BIT of 16 or 32 or even 64,
> there would be nothing wrong with that.

Quite true, but see above.

> There is one proviso to that: though never says so explicitly, for I/O
> to work correctly (specifically for EOF to be unique from any input that
> could have been read from the file) the range of int has to be greater
> than (not equal to) the range for char.  IOW, if there are 64 bits in
> the value representation of a char, then there had better be at least 65
> bits in an int, or the I/O model no longer works.

Excellent point - but, as you point out, not explicitly stated nor
immediately obvious.

-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/ Web graphics development:
http://Image-Magicians.com/ Software archives:
http://snippets.snippets.org/
  c.snippets.org/   cpp.snippets.org/      java.snippets.org/
  d.snippets.org/   python.snippets.org/   perl.snippets.org/
  dos.snippets.org/ embedded.snippets.org/ apps.snippets.org/
Audio and loudspeaker design:
  http://LDSG.snippets.org/   http://www.diyspeakers.net/

--- BBBS/LiI v4.01 Flag-5
* Origin: Prism bbs (1:261/38)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.