When is a cast not a cast?

Blair P. Houghton bph at buengc.BU.EDU
Thu May 4 03:13:41 AEST 1989


In article <10191 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <2747 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>>10 	p = (c + (char *) i);  /* More trouble than it's worth... */
>
>Addition of pointers is a meaningless operation.

Philosophically, it's rubbish.  According to the language def., it's pure
science.

Apparently, in C, one can not only add apples to oranges and get more
oranges, one can add nothing but apples to the oranges, not even oranges
themselves.

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...) but I find it more than
unsettling that a pointer offset can not be expressed and manipulated
directly in the pointer type.  At least, not without first multiplying or
dividing by the proper sizeof(*type).

				--Blair
				  "A little older,
				   marginally wiser..."



More information about the Comp.lang.c mailing list