Date: Fri, 1 Feb 2002 08:11:20 +0100 From: Erik Trulsson <ertr1013@student.uu.se> To: Cliff Sarginson <cliff@raggedclown.net> Cc: freebsd-questions@freebsd.org Subject: Re: unsigned char portability Message-ID: <20020201071119.GA17682@student.uu.se> In-Reply-To: <20020201031412.GA1950@raggedclown.net> References: <F74DyNdauuNi4kysRWz00010abe@hotmail.com> <a3cdi5$19e5$1@kemoauc.mips.inka.de> <20020201031412.GA1950@raggedclown.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <carey_june@hotmail.com> 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.) -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020201071119.GA17682>