When is a cast not a cast?
Richard Tobin
richard at aiai.ed.ac.uk
Sat May 20 03:51:26 AEST 1989
In article <334.nlhp3 at oracle.nl> bengsig at oracle.nl (Bjorn Engsig) writes:
>>>In article <406 at skye.ed.ac.uk> richard at aiai.UUCP (Richard Tobin) writes:
>>>> t = p + q;
>char *p, *q;
>
>and let p==3 and q==5. Then what is p+q? Which type does it have?
I'm not of course suggesting that this should be added to C. However,
I don't think it would be *impossible* to specify semantics for it.
p+q would have type "sum of 2 pointers to char". Subtracting a pointer
to char would give a pointer to char. Adding a pointer to char would
give "sum of 3 pointers to char". Adding a pointer to int would give
"sum of 2 pointers to char and a pointer to int". (We of course need
some canonicalisation here.) Dereferencing would of course be illegal.
It might be an error to mix pointers to different aggregates.
Just to reiterate, I don't think this should really be done. I would
hope that a compiler would generate good enough code for my original
example, but I haven't seen one that does.
-- Richard
--
Richard Tobin, JANET: R.Tobin at uk.ac.ed
AI Applications Institute, ARPA: R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin
More information about the Comp.lang.c
mailing list