Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!rutgers!nike!ucbcad!zen!cory.Berkeley.EDU!chapman From: chapman@cory.Berkeley.EDU (Brent Chapman) Newsgroups: net.lang.c,net.micro.pc Subject: Re: Signed char - What Foolishness Is This! Message-ID: <661@zen.BERKELEY.EDU> Date: Mon, 20-Oct-86 20:09:44 EDT Article-I.D.: zen.661 Posted: Mon Oct 20 20:09:44 1986 Date-Received: Wed, 22-Oct-86 01:17:24 EDT References: <8719@duke.duke.UUCP> <8273@sun.uucp> <14@ems.UUCP> Sender: news@zen.BERKELEY.EDU Reply-To: chapman@cory.Berkeley.EDU.UUCP (Brent Chapman) Organization: UNIXversity of California at Berkeley Lines: 56 Xref: watmath net.lang.c:10780 net.micro.pc:10599 In article <14@ems.UUCP> mark@ems.UUCP (Mark Colburn) writes: >It is important to note that K&R define that: > > char 8 or more bits > short 16 or more bits Just _WHERE_ does K&R say this? No place that I've ever seen... The only thing that I can figure is that you are inferring these "minimum" values from the table of _sample_ type sizes on p. 34; this is not a good thing to do. Note to everyone: If you're going to quote from something, especially K&R, _please_ check to make sure it says what you _think_ it says, and then include the page number of the info which supports your posting. >Although these values may be implementation specific. On my 68020 based >machine, shorts are 16 bits. When I need an 8 bit unsigned value (e.g. a byte) >in my code (which happens quite frequently when you are writing software to >support 8 bit CPU's) I use 'unsigned char'. > >I got myself into all sorts of trouble when I was first using C because I >assumed that if an int is 16 bits, then a short must be 8. Right? Wrong! Definitely wrong. On p. 34, K&R say "The intent is that short and long should provide different lengths of ingeters _where practical_ [emphasis mine -- Brent]; int will normall reflect the most "natural" size for a particular machine. As you can see, each compiler is free to interpret short and long as appropriate for its own hardware. About all you should count on is that short is no longer than long." Nowhere (that I'm aware of, anyway, and I looked carefully for it) does K&R say that ints must be at least 16 bits, nor that chars must be at least 8 bits. I seem to recall hearing about some screwey machine whose "character size" and "most natural integer size" were both 12 bits; for that machine, types 'char', 'int', and 'short' were all 12-bit quantities. >Therefore, the only portable way to express a true byte (8-bit) value is with >an 'unsigned int' declaration. This may still get you into trouble when you >are working on a compiler that uses characters that are more than 8 bits. 'unsigned int'? Are you sure you don't mean 'unsigned char'? But even if you do, there's no guarantee that you get what you call a "true byte"; there's nothing in K&R that outlaws a 7-bit char, for instance. The definiton of char (again, on p. 34) is "a single byte, capable of holding one character in the local character set". Note that "byte" doesn't automatically mean "8 bits". Brent chapman@cory.berkeley.edu or ucbvax!cory!chapman -- Brent Chapman chapman@cory.berkeley.edu or ucbvax!cory!chapman