0

Reference to "rvalue" in C11 standard is limited to following footnote.

"What is sometimes called ‘‘rvalue’’ is in this International Standard described as the ‘‘value of an expression’’"

where as ken Thompson's B manual uses the terms lvalue & rvalue heavily. please note the &,++ operators below ( excerpt from B manual)

rvalue ::=
    ( rvalue )
    lvalue
    constant
    lvalue assign rvalue
    inc-dec lvalue
    lvalue inc-dec
    unary rvalue
    & lvalue
    rvalue binary rvalue
    rvalue ? rvalue : rvalue
    rvalue ( {rvalue {, rvalue}0 }01 )
lvalue ::=
    name
    * rvalue
    rvalue [ rvalue ]

similarly C++ seems to have a description of lvalue to rvalue conversions (lvalue_to_rvalue1) and lvalue_to_rvalue2

I have few questions regarding the above statements.

  1. is there such a "reference"(links etc) exist for operators in C "similar" to B manual requirement of operators in lvalue & rvalue terms? ( please see that I am familiar with lvalue requirements of certain C operators)

  2. the term "rvalue" is widely used in B and used in C++, why is this missing in C?

  3. is lvalue to rvalue conversions are specific to C++ and not for C (covered indirectly by the standard), if covered will you please quote the relevant sections from standard?

Community
  • 1
  • 1
bare_metal
  • 1,134
  • 9
  • 20
  • The C11 description of an rvalue as the result of an express seems quite straightforward. C++ compilers do a lot more conversions and translations so the rules are complex since constructors and destructors and a lot of other plumbing is involved. See [lvalue and rvalue](http://stackoverflow.com/questions/2038414/lvalue-and-rvalue) – Richard Chambers Oct 26 '14 at 15:29
  • possible duplicate of [Lvalues and Rvalues in C](http://stackoverflow.com/questions/10646823/lvalues-and-rvalues-in-c) – mpromonet Oct 26 '14 at 16:50
  • @mpromonet - The question you referred is more to do with what are lvalues and rvalues. current question is more about whether there is a comprehensive list available as similar to the one pasted from B language,why their is separation in definition between C/C++ , and why C departed from the notion used in B and in C++ – bare_metal Oct 26 '14 at 17:56

2 Answers2

2

The difference between C and C++ regarding to rvalues is probably the function overloading and references.

In C, however, rules are pretty simple: the left operand several operators must be lvalues. Any other other operand can be an l-value or an rvalue. A quick search through the C99 standard gives as requirements for lvalues:

  • prefix increment and decrement operator
  • postfix increment and decrement operator
  • unary & operator
  • left of any assignment operator

So there is no necessity to put a name to the value of an expression (rvalue). They are just expressions, and their value is used.

About when an lvalue is produced:

  • an identifier (a variable)
  • a string literal
  • a lvalue in parentheses
  • the result of the access-to-member . operator, if the left operand is an lvalue
  • the result of the pointer-to-member -> operator
  • a compound literal (for example (int[]{1,2})
  • the result of the unary * operator
  • the result of the index operator []

Notably, these are not lvalues (some of them are/may be lvalues in C++, left as an exercise to the reader):

  • the result of a cast
  • the result of the conditional ternary operator ?:
  • the result of the assignment operator =
  • the result of the comma operator ,

Why is used in C references, even if there is not in the C standard? Well, it is much easier to say rvalue than to say value of an expression. And the term is familiar enough not to create any confusion.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • but the requirement of lvalue for certan operators also creates the necessity to know which operations creates lvalue and rvalue. for eg a cast operator or & operator doesn't produce lvalue making &i++ or (int)i++ invalid. if we look at the B grammar above it is clear which one is an lvalue. please see the confusion created http://stackoverflow.com/questions/7446489/casting-a-pointer-does-not-produce-an-lvalue-why – bare_metal Oct 26 '14 at 16:01
  • @bare_metal: You are right, and those are covered in the standard too. But I think that you didn't ask for these details, did you? Anyway, I can summarize them if you wish. – rodrigo Oct 26 '14 at 16:03
  • that would be nice, but when you summarize eventually wont it look something similar to the grammar shown in B? (to say +a, a+1 is an rvalue, you might need to say unary operator except certain operators, then binary and so on ). it would be great if you can point out if such a link is existing or if a similar list can be compiled. – bare_metal Oct 26 '14 at 16:08
  • @bare_metal: The difference between rvalues and lvalues is not in the grammar, but in the comments. I'll add that in a minute or two. – rodrigo Oct 26 '14 at 16:10
0

I am posting an answer to this hoping that it might help someone who is looking for the same thing. I found the operator classification table based on lvalue/rvalue in Kenneth A.Reek's Book "Pointers On C". section 5.4.3 of this book has an operator precedence table with the lexp/rexp requirement of each operator ( whether the operands of the operator is lexp/rexp and whether the result is an lexp/rexp).please note that this is based on C89.

bare_metal
  • 1,134
  • 9
  • 20