incrementing after a cast

Kenneth R. Ballou ballou at brahms
Tue Dec 9 06:22:07 AEST 1986


In article <1762 at batcomputer.tn.cornell.edu> braner at batcomputer.UUCP (braner) writes:
>[]
>
>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

Thank you.  Exactly what is *it*?  *It* is the VALUE of the pointer.  This is
what is called "r-value" in Kernighan and Ritchie, and in Harbison and Steele.

> 			  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!

WRONG.  Do you have any clue what the difference is between "l-value" and
"r-value"?  A CAST DOES NOT PRODUCE AN L-VALUE!  I quote from Kernighan and
Ritchie, page 187:

	    An expression preceded by the parenthesized name of a data
	type causes conversion of the value of the expression to the
	named type.  This construction is called a 'cast.'

Then again, here is another quotation from Harbison and Steele, page 152:

	    The cast causes the operand value to be converted to the
	type named within the parentheses.  Any permissible conversion
	may be invoked by a cast expression.  The result is not an
	lvalue.

>I see no TECHNICAL obstacle here, only "legal" morass...

	May I then suggest you look again.  It seems to me that if something
is not an l-value, the compiler is not to use it as an l-value.

Perhaps I could put in a good word with Santa Claus and ask him to leave
you a copy of K&R, or maybe even Harbison & Steele?

--------
Kenneth R. Ballou		ARPA: ballou at brahms.berkeley.edu
Department of Mathematics	UUCP: ...!ucbvax!brahms!ballou
University of California
Berkeley, California  94720



More information about the Comp.lang.c mailing list