what is the order of evaluation
Attachments:
Answers
Answered by
0
Order of evaluation of the operands of almost all C++ operators (including the order of evaluation of function arguments in a function-call expression and the order of evaluation of the subexpressions within any expression) is unspecified. The compiler can evaluate operands in any order, and may choose another order when the same expression is evaluated again.
There are exceptions to this rule which are noted below.
Except where noted below, there is no concept of left-to-right or right-to-left evaluation in C++. This is not to be confused with left-to-right and right-to-left associativity of operators: the expression f1() + f2() + f3() is parsed as (f1() + f2()) + f3() due to left-to-right associativity of operator+, but the function call to f3 may be evaluated first, last, or between f1() or f2() at run time.
Sequenced-before rules (since C++11)
Definitions
Evaluations
There are two kinds of evaluations performed by the compiler for each expression or subexpression (both of which are optional):
value computation: calculation of the value that is returned by the expression. This may involve determination of the identity of the object (glvalue evaluation, e.g. if the expression returns a reference to some object) or reading the value previously assigned to an object (prvalue evaluation, e.g. if the expression returns a number, or some other value)
side effect: access (read or write) to an object designated by a volatile glvalue, modification (writing) to an object, calling a library I/O function, or calling a function that does any of those operations.
Ordering
"sequenced-before" is an asymmetric, transitive, pair-wise relationship between evaluations within the same thread.
If A is sequenced before B, then evaluation of A will be complete before evaluation of B begins.
If A is not sequenced before B and B is sequenced before A, then evaluation of B will be complete before evaluation of A begins.
If A is not sequenced before B and B is not sequenced before A, then two possibilities exist:
evaluations of A and B are unsequenced: they may be performed in any order and may overlap (within a single thread of execution, the compiler may interleave the CPU instructions that comprise A and B)
evaluations of A and B are indeterminately sequenced: they may be performed in any order but may not overlap: either A will be complete before B, or B will be complete before A. The order may be the opposite the next time the same expression is evaluated..
this is my answer.
There are exceptions to this rule which are noted below.
Except where noted below, there is no concept of left-to-right or right-to-left evaluation in C++. This is not to be confused with left-to-right and right-to-left associativity of operators: the expression f1() + f2() + f3() is parsed as (f1() + f2()) + f3() due to left-to-right associativity of operator+, but the function call to f3 may be evaluated first, last, or between f1() or f2() at run time.
Sequenced-before rules (since C++11)
Definitions
Evaluations
There are two kinds of evaluations performed by the compiler for each expression or subexpression (both of which are optional):
value computation: calculation of the value that is returned by the expression. This may involve determination of the identity of the object (glvalue evaluation, e.g. if the expression returns a reference to some object) or reading the value previously assigned to an object (prvalue evaluation, e.g. if the expression returns a number, or some other value)
side effect: access (read or write) to an object designated by a volatile glvalue, modification (writing) to an object, calling a library I/O function, or calling a function that does any of those operations.
Ordering
"sequenced-before" is an asymmetric, transitive, pair-wise relationship between evaluations within the same thread.
If A is sequenced before B, then evaluation of A will be complete before evaluation of B begins.
If A is not sequenced before B and B is sequenced before A, then evaluation of B will be complete before evaluation of A begins.
If A is not sequenced before B and B is not sequenced before A, then two possibilities exist:
evaluations of A and B are unsequenced: they may be performed in any order and may overlap (within a single thread of execution, the compiler may interleave the CPU instructions that comprise A and B)
evaluations of A and B are indeterminately sequenced: they may be performed in any order but may not overlap: either A will be complete before B, or B will be complete before A. The order may be the opposite the next time the same expression is evaluated..
this is my answer.
Similar questions
Hindi,
8 months ago
Hindi,
8 months ago
Math,
8 months ago
Political Science,
1 year ago
Hindi,
1 year ago