"sequenced before" and "Every evaluation in the calling function" in c++ -


every evaluation in calling function (including other function calls) not otherwise sequenced before or after execution of body of called function indeterminately sequenced respect execution of called function.

in other words, function executions not interleave each other.

what meaning of "every evaluation".

#include <iostream> using namespace std; int = 0; ing b = 0; int f(int,int) {     cout << "call f, ";     cout << "a=" << << ", ";     cout << "b=" << b << ", ";     return 1; }  int g() {     cout << "call g, ";     cout << "a=" << << ", ";     cout << "b=" << b << ", ";     return 1; }  int main() {     f(a++, b++) + g();     return 0; } 
  1. it menas evaluation of function call expression f(a++, b++), evaluation of a++, evaluation of b++, , execution of f sequenced before or after execution of g.

    in case, there 2 kinds of results. if evaluation of expression f(a++, b++) sequenced before execution of g:

    call f, a=1, b=1, call g, a=1, b=1,

    if execution of g issequenced before evaluation of expression f(a++, b++):

    call g, a=0, b=0, call f, a=1, b=1,

2.it means evaluation of a++, evaluation of b++, or execution of f.

so evaluation of a++ may sequenced before execution of g, evaluation of b++ , execution of f may sequenced after execution of g.

call g, a=1, b=0, call f, a=1, b=1, 
  1. it means value computation or side effect.

so value computation of a++ may sequenced before execution of g, side effect of a++, evaluation of b++ , execution of f may sequenced after execution of g.

call g, a=0, b=0, call f, a=1, b=1, 

in case,

f(a++, b++) + (a = g()); 1.value computation of a++ 2.execution of g 3.side effect of a++ 4.side effect of = (a = 0) 5.evaluation of b++ 6.execution of f  call g, a=0, b=0, call f, a=0, b=1, 

which 1 right? or other answer?

i'm not english speaker, , i'm not @ english.

i hope can understand say

f(h1(), h2()) + g(h3(), h4())

h1 , h2 sequenced before f, h3 , h4 sequenced before g.

is possible:

  1. h1

  2. h4

  3. h2

  4. f

  5. h3

  6. g

[expr.post.incr]/1 ... value computation of ++ expression sequenced before modification of operand object. respect indeterminately-sequenced function call, operation of postfix ++ single evaluation. [ note: therefore, function call shall not intervene between lvalue-to-rvalue conversion , side effect associated single postfix ++ operator. —end note ]...

my reading of side effects of a++ , b++ must complete before body of f executed, , therefore within f must a==1 , b==1. examples #2 , #3 not possible conforming implementation.

a call g indeterminately sequenced call f, , can observe either pre-increment or post-increment values.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -