is f().c legal? How about (&(f()))->c ?

Mike McNelly mike at hpfcdc.HP.COM
Fri Feb 3 02:48:41 AEST 1989


> Here f() returns a structure.

> I am trying to figure out why C compilers like the latter expression
> and cant handle the first expression.  From what I gather from the
> ANSI specs, it says that a function call is not an lvalue (*).  Therefore
> the latter expression should be illegal (& requires an lvalue).

> As far as I can tell the first expression is legal... the . operator
> anly requires that the left hand side be a struct or union, it does not
> have to be an lvalue.

> So why is it that the C compilers (Sun and HP-UX's) both complain that
> the expression f().c is illegal, but run fine on (&(f()))->c.

> Seems to me that the logic is reversed here.

You're correct. We consider the behavior to be a bug, too. The problem of 
f().c has been fixed for release 6.5 on HP-UX Series 300 due to be released
"real soon now". I have no information on the (&(f()))->c problem.

Mike McNelly	mike%hpfcla at hplabs.hp.com



More information about the Comp.std.c mailing list