When is a cast not a cast?

Guy Harris guy at auspex.auspex.com
Sat May 20 19:57:42 AEST 1989


 >Needless to say, I laughed out loud.  He was wrong, and so were you.
 >I'm not looking at implementation, and I've described some lunatic ones
 >to prove that using an implementation for support of an argument is
 >fallacious, specious, and ingermane.  Pointers are to ignore such things.
 >If I had the bucks, I'd build a memory that resided on eleven different
 >campuses, and store all my strings of eleven chars or more in eleven
 >different states, possibly three or four countries, one char per university.
 >Doesn't mean I still wouldn't want the compiler to know _how_ to handle
 >
 >	char *bar;
 >	char *foo="elevenchars";
 >
 >	bar = &4[foo] + &foo[6];
 >	bar -= &foo;
 >
 >	fprintf(stdcontinent,"%c\n",*bar);
 >
 >and print 
 >
 >	s
 >
 >on the output file/device/metaphysicalconstruct.

Well, then, in that case you, the person proposing the notion of
"addition of pointers", must:

	1) supply an implementation-independent meaning for addition
	   of pointers, sufficient to allow the implementer of the
	   compiler to know how addition of pointers from said different
	   states is to be interpreted;

or

	2) leave it up to somebody else to supply such a meaning, and be
	   willing at some point to accept their assertion that it can't
	   be done if they so assert (otherwise, unbounded amounts of
	   your time *and* their time can be spent arguing the point,
	   and while you may not mind this, I suspect they might);

if you actually want this feature accepted.  (*Somebody* has to give it
a meaning, otherwise there are no constraints on the implementer - they
can just say "the sum of two pointers, both of some given type, is a
null pointer of that given type" and leave it at that; such a meaning
wouldn't be particularly useful.)

I take it from your insistence that the implementation doesn't enter
into it, and that pointers aren't memory addresses, means that defining
pointer addition as "treat the bits in the pointers as if they were the
bits of some integral type, add the values you get from this operation,
and treat the bits of the result as if they were the bits of the pointer
type in question" isn't an acceptable meaning for the operation.  I
suspect you'd find it unacceptable, especially on, say, a machine with a
segmented architecture....



More information about the Comp.lang.c mailing list