When is a cast not a cast?

usenet usenet at TSfR.UUCP
Fri May 19 17:50:34 AEST 1989


In article <2908 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <546 at TSfR.UUCP> orc at TSfR.UUCP (David L. Parsons) writes:
>>In article <2890 at buengc.BU.EDU> bph at 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 at pell.uucp



More information about the Comp.lang.c mailing list