Path: utzoo!attcan!uunet!lll-winken!gauss.llnl.gov!casey From: casey@gauss.llnl.gov (Casey Leedom) Newsgroups: comp.sources.games.bugs Subject: Re: Wanderer - the saga continues :-) Message-ID: <14855@lll-winken.llnl.gov> Date: 22 Dec 88 02:57:11 GMT References: <65@poppy.warwick.ac.uk> <14811@lll-winken.llnl.gov> <2585@udccvax1.acs.udel.EDU> Sender: usenet@lll-winken.llnl.gov Reply-To: casey@gauss.llnl.gov.UUCP (Casey Leedom) Organization: Lawrence Livermore National Laboratory Lines: 70 | From: evh@vax1.acs.udel.EDU (Troy Saville) | | I think you should think before you talk. K&R C says that an int is | greater than or equal to the size of a short (dependent on the system | being used). So if it isn't equal, then there is a portability problem | isn't there??? (slow down, you might have to think about this...). You're right, I probably shouldn't have bothered sending that letter off. It's at times like this that I wish I maintained an outgoing mail queue. Someone else sent me a letter privately saying nearly the same thin and I sent him a long and reasoned response. I just don't have the energy to go into that much detail right now, so I'll offer the encapsulated version. K&R says (guarantees): sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) with only those assumptions it's basically impossible to write anything portably because you have no idea how large a number you can store in any of the integral types. One of the things which has made C as portable as it is is the implicitly agreed upon, but illegitimate further assumption that: sizeof(char) == 8-bits sizeof(short) == 16-bits sizeof(long) == 32-bits and sizeof(int) == sizeof(short) or sizeof(int) == sizeof(long) These are hackneied assumptions to enable people to make some assumptions about how large a value they can store reliably in the various integral types. These give you sizeof(char) < sizeof(short) == sizeof(int) < sizeof(long) or sizeof(char) < sizeof(short) < sizeof(int) == sizeof(long) A much better approach would be for the programmer to declare what range of values the type needed to hold and let the compiler pick the appropriate machine type, but we're dealing with C and the real world here. In this particular case, my bitching was without point because xwanderer will probably never be ported to a machine where sizeof(int) == sizeof(short) (PDP-11s, 8086, etc.) What I'm really objecting to is the cavalier attitude involved in the original statement as to the capabilities of the type "int". Back in the Bad Old Days of the PDP-11, code was rife with the assumption that sizeof(int) == sizeof(short). Then the Young Turks on Vaxes came around and started spreading their seed about and it was full of sizeof(int) == sizeof(long). Because of the various problems that both these styles caused, we've tried to be more careful of recent. Basically, if we're going to have to live with our implicit, but unblessed assumptions about the sizes of char's, short's, and long's, we should be careful to use int's only where we know that the maximum values expected to be stored can fit in a short (16-bits). In those cases, we use short's when we're concerned with memory, and int's when we're concerned with performance (many 32-bit CPUs suffer significant performance loss for various operations when having to deal with short's). In the end, hopefully C will die a quiet death and a language will rise up to replace it that doesn't suffer these problems. In any case, sorry for the original posting and it's tone. It neither fit this group, nor was the tone productive. But do please try to be more careful with your assumptions about C. C is bad enough as it is without making it worse. Casey