Convert Lvalue to Rvalue

From 4.1 / 2

The value contained in the object indicated by the value of l is the rvalue result. When the conversion of lvalue-rvalue occurs inside the operand sizeof (5.3.3), the value contained in the reference object does not have access, since this operator does not evaluate its operand.

Out of curiosity, I was wondering if the same applies to if, for while statements, that is, does an lvalue convert to an rvalue when evaluating the result of an expression?

+6
source share
2 answers

Yes. Without lvalue-to-rvalue conversion, it cannot read its value.

In short, think of lvalue as some container and rvalue as the value contained in the container.

C ++ 03, section ยง3.10 / 7 states,

Whenever an lvalue appears in the context where an r value is expected, the value of l is converted to an rvalue; see 4.1, 4.2 and 4.3.

Read it along with ยง4.1 / 2 (your quote),

The value contained in the object indicated by lvalue is the result of rvalue.

Related topic:

+7
source

The answer is yes.

If bool rvalue is expected, the conversion is applied. Let test be a variable to see an example:

 if( test ) 

The test rvalue, true or false, is evaluated inside the if.

+3
source

Source: https://habr.com/ru/post/897557/


All Articles