Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Jun 1997 13:15:17 -0700
From:      "Tim Oneil" <toneil@visigenic.com>
To:        hackers@FreeBSD.ORG
Subject:   Re: signed/unsigned cpp
Message-ID:  <3.0.32.19970604131514.00a368e0@visigenic.com>

next in thread | raw e-mail | index | archive | help
At 05:00 AM 6/5/97 +1000, you wrote:
>>> Actually, 'char' is a fine, useful and portable type, if you use it for
>>> 7-bit characters, or integers 0..127. 
>>
>>Not at all portable. Char, either signed or unsigned, is _not_ guaranteed 
>>to occupy 8 bits, and you're _not_ guaranteed by the standard that
>>there's enough room in char for 7-bit numbers.
>
>Nope.  Standard C guarantees:
>
>	CHAR_BIT >= 8
>	SCHAR_MIN <= -127
>	SCHAR_MAX >= 127
>	UCHAR_MAX >= 255,
>	CHAR_MIN = SCHAR_MIN if char is signed, else 0
>	CHAR_MAX = SCHAR_MAX if char is signed, else UCHAR_MAX
>
>>There have been machines
>>in use with 6-bit chars, as well as 12-bit chars and 16-bit chars.
>
>>In C, "byte" does _not_ mean 8 bits; it means whatever number of bits
>>char takes up on this architecture. Therefore, it's true (trivially)
>>that "char takes up 1 byte", but it doesn't mean you can _portably_
>>store 127 in it ;)
>
>On machines with 6-bit characters, C compilers would have to use some
>larger size, perhaps 2 6-bit characters or one 36-bit word, to implement
>the Standard C char type.  I think the representation has to be the same
>for chars that happen to be >= 0 as for unsigned chars, so chars in the
>range [0, 127] must be stored just as (un)portably as unsigned chars
>(the representation depends on the compiler).

A byte is 8 bits, I don't care what architecture you are running
on. And what a machine uses to represent a char type is more
dependant on the compiler/machine combination's taste than
what a byte is. A byte is a group of 8 bits. A char may be a byte,
or it may be a word, or whatever. I think a char is usually defined
to be a byte, but if this is a safe assumption I'm not too sure.

-Tim




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