Path: utzoo!news-server.csri.toronto.edu!rutgers!news.cs.indiana.edu!msi.umn.edu!cs.umn.edu!uc!shamash!bls From: bls@u02.svl.cdc.com (Brian Scearce) Newsgroups: comp.lang.c Subject: Re: A quick question... Message-ID: <31306@shamash.cdc.com> Date: 13 Mar 91 00:42:50 GMT References: <1991Mar12.030759.26698@nntp-server.caltech.edu> Sender: usenet@shamash.cdc.com Lines: 30 eychaner@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@robin.svl.cdc.com -or- robin!bls@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.