A quick question...

Brian Scearce bls at u02.svl.cdc.com
Wed Mar 13 10:42:50 AEST 1991


eychaner at suncub.bbso.caltech.edu (Amateurgrammer) writes:
> Just a quick question...I personally still don't quite understand
> what is and is not legal on the left side of an assignment.

The rules are pretty easy (especially if you have your copy of
Harbison and Steele on your desk :-)

0. variable names (excepting function, array and enum constant
   names) are lvalues.
1. e[k] is an lvalue, regardless of whether e and k are lvalues.
2. (e) is an lvalue iff e is.
3. e.name is an lvalue iff e is.
4. e->name is an lvalue regardless of whether e is an lvalue.
5. *e is an lvalue regardless of whether e is an lvalue.

No other form of expression can form an lvalue.

And that's it!

Your question of what can be on the left hand side of an assignment
is slightly complicated by the ANSI separation of lvalue into
modifiable lvalue and non-modifiable lvalue, and I don't feel
qualified to post about that.  But for K&R C (and maybe ANSI C in
the absence of "const"?), the 6 rules above are all you need to
know.

--
     Brian Scearce (bls at robin.svl.cdc.com  -or-  robin!bls at shamash.cdc.com)
    "Don't be surprised when a crack in the ice appears under your feet..."
 Any opinions expressed herein do not necessarily reflect CDC corporate policy.



More information about the Comp.lang.c mailing list