From owner-freebsd-questions Thu Jan 31 23:11:53 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mailf.telia.com (mailf.telia.com [194.22.194.25]) by hub.freebsd.org (Postfix) with ESMTP id 8B99837B419 for ; Thu, 31 Jan 2002 23:11:25 -0800 (PST) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailf.telia.com (8.11.6/8.11.6) with ESMTP id g117BND28743 for ; Fri, 1 Feb 2002 08:11:24 +0100 (CET) Received: from falcon.midgard.homeip.net (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id IAA10381 for ; Fri, 1 Feb 2002 08:11:23 +0100 (CET) Received: (qmail 18104 invoked by uid 1001); 1 Feb 2002 07:11:20 -0000 Date: Fri, 1 Feb 2002 08:11:20 +0100 From: Erik Trulsson To: Cliff Sarginson Cc: freebsd-questions@freebsd.org Subject: Re: unsigned char portability Message-ID: <20020201071119.GA17682@student.uu.se> Mail-Followup-To: Cliff Sarginson , freebsd-questions@freebsd.org References: <20020201031412.GA1950@raggedclown.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020201031412.GA1950@raggedclown.net> User-Agent: Mutt/1.3.25i 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 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. 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. (There are C implementations where that is not true but that is fairly uncommon.) -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message