From owner-freebsd-hackers Wed Jun 4 12:06:07 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id MAA21600 for hackers-outgoing; Wed, 4 Jun 1997 12:06:07 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id MAA21582 for ; Wed, 4 Jun 1997 12:06:01 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.5/8.6.9) id FAA13359; Thu, 5 Jun 1997 05:00:45 +1000 Date: Thu, 5 Jun 1997 05:00:45 +1000 From: Bruce Evans Message-Id: <199706041900.FAA13359@godzilla.zeta.org.au> To: mellon@pobox.com, thompson@squirrel.tgsoft.com Subject: Re: signed/unsigned cpp Cc: hackers@FreeBSD.ORG Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >> 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