When is a cast not a cast?

Guy Harris guy at auspex.auspex.com
Thu May 4 16:08:54 AEST 1989


>Now, I don't mind being told by the compiler that I'm screwing up by
>subtracting pointers that may point to different data spaces (even though
>it is my belief that such a subtraction should occur vectorially, and
>generate the proper memory offset to get me from ram-byte A to ram-byte B,
>going through data/text/etc pages as necessary...)

Uhh, offset in *what units*?  Pointer subtraction doesn't tell you how
many "char"s there are between the pointed-to objects, it tells you how
many objects *of the storage type that the pointers both point to* (if
they point to different types, you can't subtract them) are between them
(well, that plus one - "&foo[0]" and "&foo[1]" have nothing between
them, or between them and their Calvin Klein's for that matter, but
"&foo[1] - &foo[0]" is 1), under the assumption that they both point to
members of an array of objects of that type. 

>but I find it more than unsettling that a pointer offset can not be
>expressed and manipulated directly in the pointer type.

Why?  "pointer offsets", if by that you mean "the value of one pointer
relative to another", aren't the same sorts of objects as pointers.



More information about the Comp.lang.c mailing list