From owner-freebsd-hackers Wed Jun 4 13:15:31 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id NAA02708 for hackers-outgoing; Wed, 4 Jun 1997 13:15:31 -0700 (PDT) Received: from odin.visigenic.com (odin.visigenic.com [204.179.98.2]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id NAA02690 for ; Wed, 4 Jun 1997 13:15:26 -0700 (PDT) Received: from VSI48 (vsi48.visigenic.com [206.64.15.185]) by odin.visigenic.com (Netscape Mail Server v2.02) with SMTP id AAA2339 for ; Wed, 4 Jun 1997 13:14:42 -0700 Message-Id: <3.0.32.19970604131514.00a368e0@visigenic.com> X-Sender: toneil@visigenic.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Date: Wed, 04 Jun 1997 13:15:17 -0700 To: hackers@FreeBSD.ORG From: "Tim Oneil" Subject: Re: signed/unsigned cpp Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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