Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!att!ihlpb!TSfR!usenet From: usenet@TSfR.UUCP (usenet) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Summary: the orc runs, shrieking, from the room. Message-ID: <549@TSfR.UUCP> Date: 19 May 89 07:50:34 GMT References: <2747@buengc.BU.EDU> <10191@smoke.BRL.MIL> <406@skye.ed.ac.uk> <10276@smoke.BRL.MIL> <2890@buengc.BU.EDU> <546@TSfR.UUCP> <2908@buengc.BU.EDU> Reply-To: orc@TSfR.UUCP (David L. Parsons) Followup-To: comp.lang.c Organization: This Space for Rent - Lisle, IL Lines: 57 Expires: In article <2908@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >In article <546@TSfR.UUCP> orc@TSfR.UUCP (David L. Parsons) writes: >>In article <2890@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >>[more discussion of the properties of pointer+pointer] >>> >>>>What can one legally do with it? >>> >>>What one can legally do between (consenting) integers? > >[...uses the fact that pointer-pointer now returns int to show how >associativity of pointer addition would break if we allowed pointer+pointer...] > >So, like, make pointer-pointer return the pointer. So, what will happen is that a pointer will just be another scalar, but with some additional properties that aren't subject to the operators that you'd use with a scalar? But wouldn't that kill architectures that don't have a flat address space? Building the language around a non-linear address space is a bad thing, yes, but isn't building it around a linear address space just as bad? >> What does pointer+pointer give you, aside from clever loop optimizations? > >Hey. It's arcane. So is calloc(). Then you find somewhere to use it, >and you're hopping with joy. Jeez. I'm sorry, I said that wrong. Your clever loop optimisation was _nice_ and I liked it, but my question is what other things are given, and _must_ you have pointer+pointer yields pointer to get it? In the case you gave there, pointer+pointer yields pointer_thing would do just as well, and you don't lost pointer-pointer in the process. >Allowing pointer addition and treating pointers as types would make >pointer arithmetic a consistent thing. But they already are consistant. They aren't consistant if you think of them as a scalar, but a pointer isn't a scalar- it contains an address (not a scalar) and some fieldwidth information. The examples given with latitude & longitute or street addresses show the difficulty of treating the result as a pointer. Consider, also, << and >> and floating point numbers. Does prohibiting these operators make floating-point arithmetic inconsistant? (Bitshifting a float/double gives a result that's _highly_ dependent on the FP representation used - and _what_ does bitshifting an int a fractional amount mean?) >So, one of these days I'll find >a situation, some few examples of which we've seen already, where I >will really want to do pointer+pointer... Yes. But must it break the existing relationship between pointers and integers? -david parsons -orc@pell.uucp