A subexpression is each part of a full-expression that must be individually evaluated before a final result can be determined.
For instance, 5 * 8 / 2 + 5
is a full-expression. 5 * 8
is a subexpression that evaluates to 40
, 40 / 2
is a subexpression that evaluates to 20
, and 20 + 5
is a subexpression that evaluates to 25
, the final result.
Also, looking at that, I had pondered if even the literals 5, 8, 2, and 5 are also subexpressions. But I really don't know for certain.
I forgot to answer your question in the title: No, a primary expression is not the same as an operand. For example, a; is a primary expression, but its not an operand. See also [expr.prim].
Hm. Would you say that every operand in C++ is also an expression (although not every expression can be an operand)?
On Saturday, September 3, 2016 at 11:23:39 AM UTC-4, Belloc wrote:Operands are always sub-expressions of other expressions containing them. Discarded-value expressions are not necessarily without operators. For instance, the expression a + b; is a discarded-value expression. As the name implies, its value is discarded at the end of its calculation. See [expr]/12.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
The term "operand" is defined by ISO/IEC 2382, to which ISO C++ has a normative reference. The definition is:operandentity on which an operation is performedInformally, it seems accurate to say that every operand in a C++ expression is either an expression or a braced-init-list (the right-hand side of an assignment, for instance, is an operand of that operator, but is not necessarily an expression).
On Thursday, September 8, 2016 at 2:45:14 PM UTC-3, Richard Smith wrote:The term "operand" is defined by ISO/IEC 2382, to which ISO C++ has a normative reference. The definition is:operandentity on which an operation is performedInformally, it seems accurate to say that every operand in a C++ expression is either an expression or a braced-init-list (the right-hand side of an assignment, for instance, is an operand of that operator, but is not necessarily an expression).I think we are splitting hairs a bit here, as the term operand is not formally defined in the C++ Standard,
but I have to agree with you that a braced-init-list is not an expression, when it's used as a initializer-clause of an assignment-expression.
--
The term "operand" is defined by ISO/IEC 2382, to which ISO C++ has a normative reference. The definition is:operandentity on which an operation is performedInformally, it seems accurate to say that every operand in a C++ expression is either an expression or a braced-init-list (the right-hand side of an assignment, for instance, is an operand of that operator, but is not necessarily an expression).
An expression can be as simple as a single literal or variable. The result of such an expression is the value of the literal or variable. When there are no operators present to act on them, literals and variables are not operands; they are expressions.
The term "operand" is defined by ISO/IEC 2382, to which ISO C++ has a normative reference. The definition is:operandentity on which an operation is performedInformally, it seems accurate to say that every operand in a C++ expression is either an expression or a braced-init-list (the right-hand side of an assignment, for instance, is an operand of that operator, but is not necessarily an expression).
Hm. So would this underlined bit be true as well, then? Sorry to keep dragging this topic through the mud. The specifics are causing my brain to cave in a little...
An expression can be as simple as a single literal or variable. The result of such an expression is the value of the literal or variable. When there are no operators present to act on them, literals and variables are not operands; they are expressions.
- // The simplest form of an expression is a single literal or variable:
- #include <iostream>
- int main()
- {
- // Declares a variable of type int named "whole_number":
- int whole_number;
- // The variable "whole_number" and integer literal 7 are operands of the assignment operator (=):
- whole_number = 7;
- // "whole_number" is an expression that evaluates to the value stored (7):
- whole_number;
- // The integer literal 7 is an expression that evaluates to its value (7):
- 7;
- return 0;
- }
--
Let's take a step back here: why do you care? What rule of the language involving "operands" are you trying to understand? (I think you were referring to the note in [expr] paragraph 1 in an earlier message; is that the sentence you're trying to understand?)