Does & return an lvalue?

Doug Gibbons gibbons at boulder.UUCP
Sun Apr 8 01:13:08 AEST 1984


Earlier this week I asked the net if

main()
{
	int *i, *j;
	&(*i) = j;
}

was a valid program. I was not concerned about whether or not it
compiles (depends upon your compiler). I was mainly interested here
in why anyone should think that "&*i" is an lvalue. Section
7.2 of K&R discusses both unary * and unary &. While from the description
of * it is quite obvious that *&E == E (in fact the draft standard explicitly
guarantees it), it is not at all obvious that &*E == E. Unary * will always
return an lvalue, but & is undefined in this respect. Although the above
program will compile on some implementations, I suspect that one that
will compile it is PCC based. The reason can be found in "A Tour of the
Portable C Compiler" by S.C. Johnson. In this document, we are told that
the compiler will always treat adjacent *& and &* as an identity operators.
Either the implementers were reading something into the langauge spec that
is not there, or they were taking a stand on handling an ill-defined
situation. In either case, the X3J11 ANSI should be told about this and
clean it up.



More information about the Comp.lang.c mailing list