Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #53901

Re: "lvalue"

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: "lvalue"
Date 2014-12-04 11:41 -0800
Organization None to speak of
Message-ID <ln1tofp5h9.fsf@nuthaus.mib.org> (permalink)
References (4 earlier) <547F72A6.8030502@verizon.net> <lvalue-20141204013653@ram.dialup.fu-berlin.de> <m5oi1f$jmq$1@dont-email.me> <lniohrpetm.fsf@nuthaus.mib.org> <54808F73.8040103@verizon.net>

Show all headers | View raw


James Kuyper <jameskuyper@verizon.net> writes:
> On 12/04/2014 11:20 AM, Keith Thompson wrote:
>> James Kuyper <jameskuyper@verizon.net> writes:
>>> On 12/03/2014 07:38 PM, Stefan Ram wrote:
> ...
>>>>       or if it has the form
>>>>
>>>>         *E,
>>>>
>>>>       where E is an expression of pointer type
>>>
>>> You need to be more specific - it should be a pointer to an object type,
>>> and it must point at an actual object (6.5.3.2p4)
>> 
>> What do you mean by "it must point to an actual object"?  If E is of
>> type int*, for example, then *E is an lvalue even if E is a null
>> pointer.  Actually that last part mixes source code and execution time
>> concepts.
>
>
> (6.5.3.2p4) "If the operand points ... to an object, the result is an
> lvalue designating the object."
>
> If the operand is a pointer expression of type "pointer to object", and
> it doesn't point to an object, the expression *E has undefined behavior,
> so whether or not the result is an lvalue is irrelevant.

In my opinion that's just sloppy wording.

Quoting the whole paragraph (and using underscores to denote italics,
since my *usual notation* would be too confusing here):

    The unary * operator denotes indirection. If the operand points to a
    function, the result is a function designator; if it points to an
    object, the result is an lvalue designating the object. If the
    operand has type "pointer to _type_", the result has type
    "_type_". If an invalid value has been assigned to the pointer, the
    behavior of the unary * operator is undefined.

The wording implies that evaluating the expression yields an lvalue,
which appears to go back to the older (pre-C) meaning of "lvalue", in
which an expression could be "evaluated for its lvalue" (to determine
what object it designates) or "evaluated for its rvalue" (what C simply
calls evaluation).

(Incidentally, I haven't been able to find a reference for that older
meaning of "lvalue".)

In C terms, an expression *is* (or is not) an lvalue; it doesn't yield
an lvalue as its result.

What 6.5.3.2p4 *should* say, IMHO, is something like:

    The unary * operator denotes indirection. If the operand is of
    function pointer type, the resulting expression is a function
    designator; if it is of object pointer type, the resulting
    expression is an lvalue designating the object. If the operand has
    type "pointer to _type_", the result has type _type_". If an invalid
    value has been assigned to the pointer, the behavior of the unary *
    operator is undefined.

Possibly there should be some wording in there about void* and/or
pointers to incomplete types.

The expression *E is an lvalue (if E is of object pointer type)
regardless of the value of E.  The wording in 6.5.3.2p4 does seem to
imply otherwise; I think that's an error in the standard, similar to the
one in the C90 definition of "lvalue", that should have been corrected.

> Exception: when *E occurs in the expression &*E, neither the & nor the *
> is evaluated, so the behavior would not be undefined. The result is
> equivalent to E, except that it is not an lvalue (6.5.3.2p3), even if E
> itself is.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: "lvalue" buja <buja66@gmail.com> - 2014-12-03 18:34 +0100
  Re: "lvalue" James Kuyper <jameskuyper@verizon.net> - 2014-12-03 13:03 -0500
  Re: "lvalue" jacob navia <jacob@spamsink.net> - 2014-12-03 19:29 +0100
    Re: "lvalue" buja <buja66@gmail.com> - 2014-12-03 20:01 +0100
      Re: "lvalue" Keith Thompson <kst-u@mib.org> - 2014-12-03 12:18 -0800
      Re: "lvalue" Geoff <geoff@invalid.invalid> - 2014-12-03 12:20 -0800
      Re: "lvalue" James Kuyper <jameskuyper@verizon.net> - 2014-12-03 15:29 -0500
        Re: "lvalue" James Kuyper <jameskuyper@verizon.net> - 2014-12-03 21:48 -0500
          Re: "lvalue" Keith Thompson <kst-u@mib.org> - 2014-12-04 08:20 -0800
            Re: "lvalue" James Kuyper <jameskuyper@verizon.net> - 2014-12-04 11:44 -0500
              Re: "lvalue" Keith Thompson <kst-u@mib.org> - 2014-12-04 11:41 -0800
                Re: "lvalue" James Kuyper <jameskuyper@verizon.net> - 2014-12-04 14:50 -0500
        Re: "lvalue" Keith Thompson <kst-u@mib.org> - 2014-12-03 23:40 -0800
    Re: "lvalue" Tim Rentsch <txr@alumni.caltech.edu> - 2014-12-05 09:16 -0800

csiph-web