Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!ucbvax!sdcsvax!jww From: jww@sdcsvax.UUCP Newsgroups: comp.sys.mac Subject: Re: MPW C annoyances.... Message-ID: <2926@sdcsvax.UCSD.EDU> Date: Mon, 30-Mar-87 12:01:57 EST Article-I.D.: sdcsvax.2926 Posted: Mon Mar 30 12:01:57 1987 Date-Received: Tue, 31-Mar-87 06:24:18 EST References: <12500007@acf4.UUCP> Organization: Western Software Technology, Vista, CA Lines: 55 In article <12500007@acf4.UUCP>, spector@acf4.UUCP (David HM Spector) writes: > Size and range of data types: > int 32 Range -2,147,483,648 to ..... > > > Now, what's wrong with this picture? Well, for starters, someone should > have tried to read the motorola manual for the 68000 family of microprocessors. > Integers on the 680x0 family are 16 (sixteen) bits wide, longs are 32bits. > Whats more is that Apple (!!), in Inside Macintosh states that integers are > *16 bits*! (see Inside Macintosh, Vol. I, Pg.86, "Pascal Data Types") Actually, integers on the MC68020 and later are 32 bits wide, not 16 bits wide. The only thing that keeps the 68000 and 68010 from being a true 32-bit machine is the lack of the multiply/divide in 32 bit size. A convincing case can be made for 16 bit integers (speed, Pascal compatibility), but most C compilers for real machines nowadays (and I think the Mac II is intended to be a real machine) assume int is 32 bits. There's even the crappy code around that assumes sizeof(int) = sizeof(char *), and in fact, Apple uses this to shorten the header files for MPW C. I think the concern is less severe, because Apple has a provision to automatically coerce the size of Toolbox traps and even do a little type checking (finally! my one gripe about C.) > Why am I as a programmer forced to rewrite > (read: change) thousands of lines of code that make the (correct) assumption > that integers on a Macintosh are 16bits?!? Because you are masochist who likes to write non-portable code. :-) Every Macintosh C programmer should start his code with typedef Byte char; typedef Half short; typedef Full long; (or pick other names you like better) and expect int to be either size. The only case I can think of to use int is if you always pass an integer constant as an argument and are too lazy to coerce it each time (which can be easily solved by a macro, btw). Take a look at the news software, or kermit, two large public domain programs available in source. They run on all sorts of machines, because they make no assumptions in certain areas, such as the size of an int, or the representation of value NULL. Anyone who wants to keep their C code for more than six months starts out by programming defensively for portability; this is true for the Mac and any other machine with a C compiler, since you never know where you'll go next (compiler or machine). -- Joel West {ucbvax,ihnp4}!sdcsvax!jww (ihnp4!gould9!joel once I fix news) jww@sdcsvax.ucsd.edu if you must