incrementing after a cast

braner braner at batcomputer.tn.cornell.edu
Mon Dec 8 16:53:30 AEST 1986


[]

In article <1746 at batcomputer.tn.cornell.edu>  I wrote:
>If  ((sometype *)pointer)++ is not legal, then the law should be changed!
>(since the pointer-type cast is legal, why can't you use the resulting
>pointer like any pointer of sometype?)

In article <491 at cartan.Berkeley.EDU> ballou at brahms (Kenneth R. Ballou) wrote:
>You can use the *VALUE* of the pointer in exactly the same way as you could
>use the *VALUE* of any other pointer. ...the pre/post-increment
>operator requires one of those mythical beasts, an l-value.  Likewise, you
>could not apply pre/post-increment to the result of a function call.

- When you cast a pointer to a pointer of another type, you are telling
the compiler to use it differently (e.g. to read 2 instead of 1 byte
from memory when dereferencing).  Since the compiler is aware of the cast
in that sense, it COULD increment it according to the new type's size!
I see no TECHNICAL obstacle here, only "legal" morass...

- Moshe Braner



More information about the Comp.lang.c mailing list