From owner-freebsd-questions Fri Feb 1 1:31:14 2002 Delivered-To: freebsd-questions@freebsd.org Received: from post.mail.nl.demon.net (post-10.mail.nl.demon.net [194.159.73.20]) by hub.freebsd.org (Postfix) with ESMTP id 0C60137B400 for ; Fri, 1 Feb 2002 01:31:10 -0800 (PST) Received: from [212.238.194.207] (helo=tanya.raggedclown.net) by post.mail.nl.demon.net with esmtp (Exim 3.33 #1) id 16Wa2F-00049c-00 for freebsd-questions@freebsd.org; Fri, 01 Feb 2002 09:31:07 +0000 Received: by tanya.raggedclown.net (tanya.raggedclown.intra, from userid 500) id 4D5E644F6B; Fri, 1 Feb 2002 10:31:06 +0100 (CET) Date: Fri, 1 Feb 2002 10:31:06 +0100 From: Cliff Sarginson To: freebsd-questions@freebsd.org Subject: Re: unsigned char portability Message-ID: <20020201093106.GB1071@raggedclown.net> References: <20020201031412.GA1950@raggedclown.net> <20020201071119.GA17682@student.uu.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020201071119.GA17682@student.uu.se> User-Agent: Mutt/1.3.24i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, Feb 01, 2002 at 08:11:20AM +0100, Erik Trulsson wrote: > On Fri, Feb 01, 2002 at 04:14:12AM +0100, Cliff Sarginson wrote: > > On Thu, Jan 31, 2002 at 09:39:17PM +0000, Christian Weisgerber wrote: > > > June Carey wrote: > > > > > > > I have a question I was hoping someone could answer. > > > > Does the "unsigned char" C type have any machine architecture portability > > > > problems ? > > > > > > For one thing, you don't know its size. I'm told there are C > > > implementations on DSPs and such that have 32-bit chars, simply > > > because those processors don't support other datasizes or byte > > > addressing. Now whether you care about portability to such platforms > > > is a different matter. > > > > > > > That doesn't matter, as long as you don't take liberties on it's assumed > > size, i.e. if it matters use "sizeof", don't fiddle with it inside an aggregate > > like a struct except as a member of that struct, you can always treat is an > > unsigned 8 bit quantity even on a Risc machine, where it's "real" size > > will probably not be 8 bits (it is irrelevant whether the OS is FreeBSD > > or not). > > sizeof won't be much use there since 'sizeof(char)' (or 'sizeof(unsigned > char)') is always 1 by definition. I was referring to sizeof as applied to structs, that was not clear from the way I put it. If it matters use CHAR_BIT to find > out how many bits there are in a char. > > Oh, and on most RISC machines you have CHAR_BIT==8 also. > -ditto- above struct foo { char c; }; sizeof foo will not give the same answer on all machines I think we are confusing two things here. One is how big a char is for "practical" purposes, and how much storage space it takes on a particular machine. As long as you don't play games that involve architectural assumptions you should be ok (and before anyone says people do not do that, they do, I spent a long time clearing up a mess some hired-in programmer had made of some code by using certain assumptions). > -- > > Erik Trulsson > ertr1013@student.uu.se -- Regards Cliff To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message