summaryrefslogtreecommitdiff
path: root/devdocs/c/language%2Fvalue_category.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/language%2Fvalue_category.html')
-rw-r--r--devdocs/c/language%2Fvalue_category.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/devdocs/c/language%2Fvalue_category.html b/devdocs/c/language%2Fvalue_category.html
new file mode 100644
index 00000000..8306ec83
--- /dev/null
+++ b/devdocs/c/language%2Fvalue_category.html
@@ -0,0 +1,58 @@
+ <h1 id="firstHeading" class="firstHeading">Value categories</h1> <p>Each <a href="expressions" title="c/language/expressions">expression</a> in C (an operator with its arguments, a function call, a constant, a variable name, etc) is characterized by two independent properties: a <a href="type#Type" title="c/language/type">type</a> and a <a href="expressions#General" title="c/language/expressions">value category</a>.</p>
+<p>Every expression belongs to one of three value categories: lvalue, non-lvalue object (rvalue), and function designator.</p>
+<h3 id="Lvalue_expressions"> Lvalue expressions</h3> <p>Lvalue expression is any expression with <a href="type#Type_groups" title="c/language/type">object type</a> other than the type <code>void</code>, which potentially designates an <a href="object" title="c/language/object">object</a> (the behavior is undefined if an lvalue does not actually designate an object when it is evaluated). In other words, lvalue expression evaluates to the <i>object identity</i>. The name of this value category ("left value") is historic and reflects the use of lvalue expressions as the left-hand operand of the assignment operator in the CPL programming language.</p>
+<p>Lvalue expressions can be used in the following <i>lvalue contexts</i>:</p>
+<ul>
+<li> as the operand of the <a href="operator_member_access" title="c/language/operator member access">address-of operator</a> (except if the lvalue designates a <a href="bit_field" title="c/language/bit field">bit-field</a> or was declared <a href="storage_duration" title="c/language/storage duration">register</a>). </li>
+<li> as the operand of the pre/post <a href="operator_incdec" title="c/language/operator incdec">increment and decrement operators</a>. </li>
+<li> as the left-hand operand of the <a href="operator_member_access" title="c/language/operator member access">member access</a> (dot) operator. </li>
+<li> as the left-hand operand of the <a href="operator_assignment" title="c/language/operator assignment">assignment and compound assignment</a> operators. </li>
+</ul> <p>If an lvalue expression is used in any context other than <a href="sizeof" title="c/language/sizeof"><code>sizeof</code></a>, <a href="_alignof" title="c/language/ Alignof"><code>_Alignof</code></a>, or the operators listed above, non-array lvalues of any complete type undergo <a href="conversion" title="c/language/conversion">lvalue conversion</a>, which models the memory load of the value of the object from its location. Similarly, array lvalues undergo <a href="conversion" title="c/language/conversion">array-to-pointer conversion</a> when used in any context other than <code>sizeof</code>, <code>_Alignof</code>, address-of operator, or array initialization from a string literal.</p>
+<p>The semantics of <a href="const" title="c/language/const"><code>const</code></a>/<a href="volatile" title="c/language/volatile"><code>volatile</code></a>/<a href="restrict" title="c/language/restrict"><code>restrict</code></a>-qualifiers and <a href="atomic" title="c/language/atomic">atomic</a> types apply to lvalues only (lvalue conversion strips the qualifiers and removes atomicity).</p>
+<p>The following expressions are lvalues:</p>
+<ul>
+<li> identifiers, including function named parameters, provided they were declared as designating objects (not functions or enumeration constants) </li>
+<li> <a href="string_literal" title="c/language/string literal">string literals</a> </li>
+<li> <span class="t-mark-rev t-since-c99">(C99)</span> <a href="compound_literal" title="c/language/compound literal">compound literals</a> </li>
+<li> parenthesized expression if the unparenthesized expression is an lvalue </li>
+<li> the result of a member access (dot) operator if its left-hand argument is lvalue </li>
+<li> the result of a member access through pointer <code>-&gt;</code> operator </li>
+<li> the result of the indirection (unary <code>*</code>) operator applied to a pointer to object </li>
+<li> the result of the subscription operator (<code>[]</code>) </li>
+</ul> <h4 id="Modifiable_lvalue_expressions"> Modifiable lvalue expressions</h4> <p>A <i>modifiable lvalue</i> is any lvalue expression of complete, non-array type which is not <a href="const" title="c/language/const">const</a>-qualified, and, if it's a struct/union, has no members that are <a href="const" title="c/language/const">const</a>-qualified, recursively.</p>
+<p>Only modifiable lvalue expressions may be used as arguments to increment/decrement, and as left-hand arguments of assignment and compound assignment operators.</p>
+<h3 id="Non-lvalue_object_expressions"> Non-lvalue object expressions</h3> <p>Known as <i>rvalues</i>, non-lvalue object expressions are the expressions of object types that do not designate objects, but rather values that have no object identity or storage location. The address of a non-lvalue object expression cannot be taken.</p>
+<p>The following expressions are non-lvalue object expressions:</p>
+<ul>
+<li> integer, character, and floating constants </li>
+<li> all operators not specified to return lvalues, including </li>
+<ul>
+<li> any function call expression </li>
+<li> any cast expression (note that compound literals, which look similar, are lvalues) </li>
+<li> member access operator (dot) applied to a non-lvalue structure/union, <code>f().x</code>, <code>(x,s1).a</code>, <code>(s1=s2).m</code> </li>
+<li> results of all arithmetic, relational, logical, and bitwise operators </li>
+<li> results of increment and decrement operators (note: pre-forms are lvalues in C++) </li>
+<li> results of assignment operators (note: also lvalues in C++) </li>
+<li> the conditional operator (note: is lvalue in C++ if both the second and third operands are lvalues of the same type) </li>
+<li> the comma operator (note: is lvalue in C++ if the second operand is) </li>
+<li> the address-of operator, even if neutralized by application to the result of unary <code>*</code> operator </li>
+</ul>
+</ul> <p>As a special case, expressions of type <code>void</code> are assumed to be non-lvalue object expressions that yield a value which has no representation and requires no storage.</p>
+<p>Note that a struct/union rvalue that has a member (possibly nested) of array type does in fact designate an object with <a href="lifetime" title="c/language/lifetime">temporary lifetime</a>. This object can be accessed through lvalue expressions that form by indexing the array member or by indirection through the pointer obtained by array-to-pointer conversion of the array member.</p>
+<h3 id="Function_designator_expression"> Function designator expression</h3> <p>A function designator (the identifier introduced by a <a href="function_declaration" title="c/language/function declaration">function declaration</a>) is an expression of function type. When used in any context other than the address-of operator, <a href="sizeof" title="c/language/sizeof"><code>sizeof</code></a>, and <a href="_alignof" title="c/language/ Alignof"><code>_Alignof</code></a> (the last two generate compile errors when applied to functions), the function designator is always converted to a non-lvalue pointer to function. Note that the function-call operator is defined for pointers to functions and not for function designators themselves.</p>
+<h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 6.3.2.1 Lvalues, arrays, and function designators (p: 40) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 6.3.2.1 Lvalues, arrays, and function designators (p: 54-55) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 6.3.2.1 Lvalues, arrays, and function designators (p: 46) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 3.2.2.1 Lvalues and function designators </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/value_category" title="cpp/language/value category">C++ documentation</a></span> for <span class=""><span>Value categories</span></span> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/language/value_category" class="_attribution-link">https://en.cppreference.com/w/c/language/value_category</a>
+ </p>
+</div>