Lvalues and casts

Chris Torek chris at mimsy.UUCP
Wed May 24 08:48:00 AEST 1989


In article <847 at tub.UUCP> net at tub.UUCP (Oliver Laumann) writes:
-I just found out (by accident; I didn't want to actually use it)
-that the GNU cc with the -ansi option, the cc under SunOS 4.0 and
-the Greenhills C-compiler all happily compile the following program
-(without any warnings):
-
-    f () {
-	int *ip;
-	char *cp;
-
-	(int *)cp = ip;
-    }
-
-The PCC, however, says "illegal lvalue in assignment".  Is this legal
-C, i.e. is the result of a cast really an lvalue?

The result of a cast is not an lvalue (is an rvalue).  GCC accepts it
as an extension; the Greenhills compiler probably accepts it because
some versions of PCC did; correct PCCs reject it.

If you compile with

	gcc -ansi -pedantic

GCC does reject the assignment.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list