Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Value (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Value category == Despite its name, in the C++ language standards this terminology is used to categorize expressions, not values.<ref>{{Cite web |date=2017 |title=ISO/IEC 14882:2017 Programming languages โ C++ |url=https://www.iso.org/standard/68564.html}}</ref>{{Rp|location=8.2.1}} === {{Anchor|lrvalue}}Assignment: l-values and r-values === Some languages use the idea of '''l-values''' and '''r-values''', deriving from the typical mode of evaluation on the left and right-hand side of an assignment statement. An l-value refers to an object that persists beyond a single expression. An r-value is a temporary value that does not persist beyond the expression that uses it.<ref>{{cite web|title=Lvalues and Rvalues (Visual C++)|url=https://msdn.microsoft.com/en-us/library/f90831hc.aspx|website=Microsoft Developer Network|access-date=3 September 2016}}</ref> The notion of l-values and r-values was introduced by [[Combined Programming Language]] (CPL). The notions in an expression of r-value, l-value, and r-value/l-value are analogous to the [[Parameter (computer programming)|parameter]] modes of input parameter (has a value), [[output parameter]] (can be assigned), and input/output parameter (has a value and can be assigned), though the technical details differ between contexts and languages. ===R-values and addresses=== In many languages, notably the [[C programming language|C family]], l-values have [[memory address|storage address]]es that are programmatically accessible to the running program (e.g., via some address-of operator like "&" in C/C++), meaning that they are variables or [[Dereference operator|de-referenced]] references to a certain memory location. R-values can be l-values (see below) or non-l-valuesโa term only used to distinguish from l-values. Consider the C expression {{code|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 a non l-value. On the other hand, if a C program declares a variable x and assigns the value of 13 to x, then the expression {{code|x}} has a value of 13 and is an l-value. In C, the term l-value originally meant something that could be assigned to (hence the name, indicating it is on the left side of the assignment operator), but since the reserved word {{code|const}} (constant) was added to the language, the term is now 'modifiable l-value'. In [[C++11]] a special semantic-glyph {{code|&&}} exists ( not to be confused with the <code>[[Short-circuit evaluation#Support in common programming languages|&&]]</code> operator used for logical operations ), 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 {{code|&}} operator during the ''run-time'' of the program (see [[C++11#Rvalue references and move constructors|the use of move semantics]]). The addition of move semantics complicated the value classification taxonomy by adding to it the concept of an xvalue (expiring value) which refers to an object near the end of its lifetime whose resources can be reused (typically by moving them). This also lead to the creation of the categories glvalue (generalized lvalue) which are lvalues and xvalues and prvalues (pure rvalues) which are rvalues that are not xvalues.<ref>{{cite web|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3055.pdf|title=A Taxonomy of Expression Value Categories|author=William M. Miller}}</ref> This type of reference can be applied to ''all'' r-values including non-l-values as well as l-values. 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 [e.g., index register address] to the value.) The l-value expression designates (refers to) an object. A non-modifiable l-value is addressable, but not assignable. A modifiable l-value allows the designated object to be changed as well as examined. An r-value is any expression, a non-l-value is any expression that is not an l-value. One example is an "immediate value" (see above) and consequently not addressable.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)