Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.lang.c Subject: Re: When it is amoral... (Re: When is a cast not a cast?) Message-ID: <1558@auspex.auspex.com> Date: 4 May 89 06:55:09 GMT References: <2747@buengc.BU.EDU> <2763@buengc.BU.EDU> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 23 >It doesn't change the fact that I'd like to be able to add and subtract >pointers regardless of what trouble I _might_ get into. Considering the >general level of danger incurred by programming in something so potentially >obfuscatory as C, it's a small barrier to remove. I guess the question is "what do you expect to happen when you add pointers?" The definition of "pointer + int" doesn't refer to low-level bit-banging - i.e., the "multiply by the size of the object and then add the (binary) values of the pointer and the result of the multiplication" is perhaps more of a guide to understanding for people unfamiliar with C-style pointer addition but familiar with bit-banging, and a guide to the implementer, than a definition. (Check out the Dec. 7, 1988 draft - the "multiply by the size of the object..." stuff is relegated to a footnote.) Can you come up with a similar definition for the addition of two pointers? If not, it sounds like it may be implementation-dependent, in which case C implementations may let you do what you want by casting the pointers properly (perhaps to some integral type), in which case you *could* do what you want - you just have to say "pretty please" to the C compiler. I have no problem whatsoever with that; I *like* it when the compiler discovers I've screwed up when it detects a type mismatch - it saves me from discovering it at run time. Think of it as a fail-safe.