Value (computer Science) - Assignment: L-values and R-values

Assignment: L-values and R-values

Some languages use the idea of l-values and r-values. Lvalues are values that have addresses being programmatically accessible to the running program (e.g., via some address-of–operator like "&" in C/C++), meaning that they are variables or dereferenced references to a certain memory location. Rvalues can be lvalues (see below.) or non-lvalues—a term only used to distinguish from lvalues. Consider the C expression (4 + 9). When executed, the computer generates an integer value of 13, but because the program has not explicitly designated where in the computer this 13 is stored, the expression is an rvalue. On the other hand, if a C program declares a variable x and assigns the value of 13 to x, then the expression (x) has a value of 13 and is an lvalue.

In C, the term lvalue originally meant something that could be assigned to (coming from left-value, indicating it was on the left side of the assignment operator), but since 'const' was added to the language, this now is termed a 'modifiable lvalue'. In C++11 a special semantic-glyph "&&" exists, to denote the use/access of the expression's address for the compiler only, i.e. the address cannot be retrieved using the "&"–address-of–operator during the run-time of the program (see the use of move semantics). This type of reference can be applied to all r-values including non-lvalues as well as lvalues. Some processors provide one or more instructions which take an "immediate value", sometimes referred to as "immediate" for short. An immediate value is stored as part of the instruction which employs it, usually to load into, add to, or subtract from, a register. The other parts of the instruction are the opcode, and destination. The latter may be implicit. (A non-immediate value may reside in a register, or be stored elsewhere in memory, requiring the instruction to contain a direct or indirect address to the value.)

The lvalue expression designates (refers to) an object. A non-modifiable lvalue is addressable, but not assignable. A modifiable lvalue allows the designated object to be changed as well as examined. An rvalue is any expression, a non-lvalue is any expression that is not an lvalue. One example is an "immediate value" (look below) and consequently not addressable.

The notion of lvalues and rvalues was introduced by CPL.

Read more about this topic:  Value (computer Science)