Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 1997 05:00:45 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        mellon@pobox.com, thompson@squirrel.tgsoft.com
Cc:        hackers@FreeBSD.ORG
Subject:   Re: signed/unsigned cpp
Message-ID:  <199706041900.FAA13359@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> 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).

Bruce



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