Definition of lvalue (was: address of function's return value)

Definition of lvalue (was: address of function's return value)

Post by Army198 » Sun, 30 Sep 2007 17:20:35



[About wheter *(int *)NULL is a lvalue]

What a mess... The funniest thing is that in eight years since
C99 to TC3 (n1256) nobody noticed that. Of course 6.3.2.1 isn't
intended to mean that 42 is a lvalue, and since it doesn't
designate an object the behavior is undefined when it is
evaluated.

Maybe a definition such "A lvalue is an identifier designing an
object, a string literal, or the result of operators [ ], ->, .
and unary *, provided that they don't violate any constraint, and,
in the case of ., that the left operand is a lvalue." would do
that, wouldn't it? (Maybe compound literals, too?)

--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.
 
 
 

Definition of lvalue (was: address of function's return value)

Post by Keith Thom » Mon, 01 Oct 2007 04:22:44

Army1987 < XXXX@XXXXX.COM > writes:


Well, I noticed it before TC3 came out (though I'm having trouble
finding the thread on comp.std.c; I *thought* the subject was
something like "Is 42 an lvalue", but Google can't find it).


I think the C90 definition, that

An _lvalue_ is an expression (with an object type or an incomplete
type other than void) that designates an object.

was *almost* correct. It just needed some added wording to say that
an expression can be an lvalue even if it doesn't happen to designate
an object when it's evaluated, as long as it *could* do so.

I suggest:

An _lvalue_ is an expression (with an object type or an incomplete
type other than void) that designates an object, or that could
designate an object.

with a footnote saying that the last clause covers cases like
``int *ptr = NULL;'', where ``*ptr'' is an lvalue even though
it doesn't currently designate an object.

The "could designate" wording isn't precise enough for my taste, but I
haven't seen a better proposal. It's certainly better than having a
definition that's just wrong.

--
Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.yqcomputer.com/ ~kst>
San Diego Supercomputer Center <*> < http://www.yqcomputer.com/ ~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

 
 
 

Definition of lvalue (was: address of function's return value)

Post by pete » Mon, 01 Oct 2007 05:45:07


http://www.yqcomputer.com/

Back in 2002, we used to use 5 instead of 42
as the example for this particular topic.
Pai-Yi HSIAO was the first to bring it to my attention.
I argued and lost.

My impression is that the C standard committee is not
strongly motivated to fix any part of the standard
that isn't actually causing a problem for a C implementor.

--
pete