Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: comp.lang.c Subject: Re: incrementing after a cast Message-ID: <518@cartan.Berkeley.EDU> Date: Mon, 8-Dec-86 15:22:07 EST Article-I.D.: cartan.518 Posted: Mon Dec 8 15:22:07 1986 Date-Received: Mon, 8-Dec-86 21:46:13 EST References: <349@apple.UUCP> <7376@utzoo.UUCP> <1746@batcomputer.tn.cornell.edu> Sender: daemon@cartan.Berkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Organization: Math Dept. UC Berkeley Lines: 52 Keywords: cast, increment, postincrement In article <1762@batcomputer.tn.cornell.edu> braner@batcomputer.UUCP (braner) writes: >[] > >In article <1746@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@cartan.Berkeley.EDU> ballou@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@brahms.berkeley.edu Department of Mathematics UUCP: ...!ucbvax!brahms!ballou University of California Berkeley, California 94720