Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 v7 ucbtopaz-1.8; site ucbtopaz.CC.Berkeley.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ucbvax!ucbtopaz!mwm From: mwm@ucbtopaz.CC.Berkeley.ARPA Newsgroups: net.lang.c Subject: Re: integer types, sys calls, and stdio Message-ID: <709@ucbtopaz.CC.Berkeley.ARPA> Date: Thu, 7-Feb-85 22:24:07 EST Article-I.D.: ucbtopaz.709 Posted: Thu Feb 7 22:24:07 1985 Date-Received: Sat, 9-Feb-85 08:53:28 EST References: <1997@mordor.UUCP> <631@turtlevax.UUCP> <550@mako.UUCP> <22@mordor.UUCP> <294@psivax.UUCP> Reply-To: mwm@ucbtopaz.UUCP (Praiser of Bob) Distribution: net Organization: Missionaria Phonibalonica Lines: 50 Summary: In article <294@psivax.UUCP> friesen@psivax.UUCP (Stanley friesen) writes: > Whitesmith has come up with a series of defined types >which can be used to increase portibility if they are used regularly. >They are defined in an include file "std.h" which can be adjusted >to each machines oddities. The types, and intended meanings are: >[list deleted - mwm] Stanley, this list is similar (in intent, anyway) to /usr/include/sys/types.h. types.h has the advantage that it doesn't tie you to some specific architecture. DRI pushes similar things with their compilers, that define "BYTE" (8 bits), "WORD" (2 bytes) and "LONG" (4 bytes). My basic reaction to all of these is the same: YUCH. Not that these things are bad, just that they aren't sufficient if you're really worried about it (for instance, how does the 7-bit chars used for TOPS-10 ASCII fit? Better yet, how about their 6-bit chars used in some places?). The correct solution to making sure that you have enough space for all your int's has already been suggested: A machine-specific series of typedefs of the form: typedefsintX ; typedef uintX ; Where X is the number of bits of magnitude that you need, sint is a smallest integer signed type with that many bits of magnitude or more, and uint is the analogous unsigned integer type (no, we will *not* worry about trinary machines and other such oddities. Yet.) Note that for an 8-bit architechture where the compiler makes "char" signed and does the least suprising thing with "unsigned char", "typedef char uint8;" works, but you have to have "typedef short sint8" to get 8 bits of magnitude out of the thing. Trouble is, one system (4BSD, or AT&T even) introducing that include file doesn't help much. Old programs would still not use it, and new programs would require you to create the include file of typedefs. Having been to lazy to do that, I use the folloing rules: Most of the time, If you're not worried about how big integer types are, use int. God help you if your int's are only 8 bits long (I don't think anyone has done that). If you need more than 16 bits, use "long". Never use char as something to hold an integer - use short for very small objects where you're worried about space. While not perfect, it doesn't create problems on screwy machines like the whitesmith/DRI plan, and comes close to working almost everywhere. Now, if only I could convince the compiler to do runtime overflow checking.