What's an LValue [was A quick question]

Sean Burke sean at hcx2.ssd.csd.harris.com
Sat Mar 16 04:41:06 AEST 1991


In article <10898 at dog.ee.lbl.gov>, torek at elf.ee.lbl.gov (Chris Torek) writes:
|> >In article <31306 at shamash.cdc.com> bls at u02.svl.cdc.com (Brian Scearce) writes:
|> >>The rules are pretty easy (especially if you have your copy of
|> >>Harbison and Steele on your desk :-)
|> 
|> [and then notes that this needs changes for ANSI C]
|> 
|> >>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.
|> 
|> In article <1991Mar13.050555.26149 at tandem.com> jimbo at tandem.com
|> (Jim Lyon) writes:
|> >Rules (1) and (5) need to be further qualified.  e[k] and *e are
|> >lvalues regardless of whether e and k are lvalues, UNLESS the type
|> >of e[k] or *e is either Array... or Function...
|> 
|> Half of the qualifier is correct for ANSI C (*e is not an lvalue if e
|> has type `pointer to function (args) returning T').  In addition, the
|> type of e[k] may never% be `function ...' because for this to be true,
|> either:
|> 
|> 	e has type `pointer to function ...'  and k has an integral type
|> 
|> or:
|> 
|> 	e has an integral type and k has type `pointer to function ...'
|> 
|> and you cannot add an integer value to a pointer-to-function-... since
|> the size of a `function-...' is unknown.&
|> 

So where would:

   struct { int array[10] ; } func() ;

   func().array[k]

fit into these rules?

I guess you could argue that its covered becuase

  func().array

is implicitly taking the address of something that is not an lvalue,
and thats an error in itself.



More information about the Comp.lang.c mailing list