Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lvalue to Rvalue conversions

From 4.1/2

The value contained in the object indicated by the lvalue is the rvalue result. When an lvalue-to-rvalue conversion occurs within the operand of sizeof (5.3.3) the value contained in the referenced object is not accessed, since that operator does not evaluate its operand.

Out of curiosity, I was wondering, does the same applies to the if, for, while statements, i.e lvalue is converted to rvalue when the result of statement is evaluated?

like image 461
parc84 Avatar asked Sep 18 '11 08:09

parc84


Video Answer


2 Answers

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

Loosely speaking, think of lvalue as some sort of container, and rvalue as the value contained in the container.

C++03, section §3.10/7 reads,

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

Read it along with, §4.1/2 (your quotation),

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

Related topic:

  • What standard clause mandates this lvalue-to-rvalue conversion?
like image 137
Nawaz Avatar answered Oct 10 '22 20:10

Nawaz


The answer is yes.

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

if( test )

Rvalue of test, true or false, is evaluated inside the if.

like image 24
robermorales Avatar answered Oct 10 '22 18:10

robermorales