Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!bbn!diamond.bbn.com!mlandau From: mlandau@bbn.com (Matt Landau) Newsgroups: comp.lang.c Subject: Arithmetic Types [WAS Re: 32bit = 16bit x 16bit] Message-ID: <9873@slate.BBN.COM> Date: Fri, 16-Oct-87 11:58:44 EDT Article-I.D.: slate.9873 Posted: Fri Oct 16 11:58:44 1987 Date-Received: Sat, 17-Oct-87 21:56:29 EDT References: <1912@gryphon.CTS.COM> Reply-To: mlandau@bbn.com (Matt Landau) Followup-To: comp.lang.c Organization: Stately Wayne Manor Lines: 41 Summary: don't count on anything - use typedefs In comp.lang.c (<1912@gryphon.CTS.COM>), mhatter@pnet02.CTS.COM (Patrick E. Hughes) writes: >In addition to a small letter I sent to the author of the original message >that started this whole mess, I might suggest one thing if you plan on porting >many C programs: Don't Use Ints > >Use char, use long, use float, and since they don't change size you're always >set. Don's change size, eh? You want signed or unsigned chars? And how many bits are there in a char anyway? Eight? Nine? Thirteen? The language doesn't specify anything about chars, or longs (except that sizeof(long) >= sizeof(int), which isn't much help), or much of anything else where the size and representation of arithmetic types are concerned. If you're concerned about being portable, use typedefs. I generally try to typedef signed and unsigned types of 8, 16, and 32 bits, and some kind of short and long flaoting point types. For most machines, the integer types work out to: typedef unsigned char UINT8; typedef unsigned char BYTE; /* I like BYTE, so what? */ typedef unsigned short UINT16; typedef unsigned int UINT32; typedef char INT8; typedef short INT16; typedef int INT32; though on Intel-based PC's and other perverse hardware, things change a bit. Note that these are *minimum* number of bits, not *exact* number of bits; Anything that requires exact sizes is probably going to need its own set of application-specific typedefs anyway. The point is, the code only uses "int" or "char" when the details don't matter and it's important to get the "best" performance (which one assumes you get by using the "natural size" integer -- that's what "int" in C *means*). If it matters how many bits something is, using the typedefs insures that the code is portable to any machine for which all of the appropriate types can be defined. -- Matt Landau Waiting for a flash of enlightenment mlandau@bbn.com in all this blood and thunder