(&f())->member, was: union *func()

Walter Murray walter at hpcllca.HP.COM
Thu Nov 3 02:30:30 AEST 1988


David Lai writs:

> On a related issue, the C language specifies that a function call is never an
> lvalue, yet most compilers I've used allow:

> 	struct xxx f();
> 	dummy = (&f())->member;

> Does anyone know if this is contrary to ANSI?
-- 
Yes, this is contrary to ANSI.  A conforming implementation will have
to diagnose this, as it violates a constraint in Section 3.3.3.2.  A
function call cannot be used as the operand of the unary & operator.

You will find the same restriction in Harbinson & Steele, 2nd ed, p. 139.
"A function call cannot produce an lvalue. ... The operand of a
unary address operator & must be an lvalue."

For that matter, K&R seems to be just as strict.  See p. 187.


Walter Murray
All opinions expressed are my own.



More information about the Comp.std.c mailing list