[net.lang.c] Does & return an lvalue?

gibbons@boulder.UUCP (Doug Gibbons) (04/07/84)

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.

ron@brl-vgr.ARPA (Ron Natalie <ron>) (04/09/84)

But the appendix in the back of K&R defines lvalue syntacally (not functionally
as you are trying to do with your definitions).  It specifically excludes "&"
followed by anything from being an LVALUE.

-Ron