Reputation: 1285
#include <iostream>
using namespace std;
int f(int){cout << "f ";return 0;}
int g(int){cout << "g ";return 0;}
int a(){cout << "a ";return 0;}
int b(){cout << "b ";return 0;}
int main()
{
f(a()) + g(b());
return 0;
}
I konw a is sequenced before f, b is sequenced before g. f and g are unsequenced.
How many results are there?
1.a f b g
2.b g a f
Example 1 and 2 may happen. How about these?
a b f g
a b g f
b a f g
b a g f
Possibly or impossible?
Upvotes: 1
Views: 60
Reputation: 56547
The only thing that's guaranteed is that b()
will be evaluated before g()
, and a()
before f()
. Those are the only 2 ordering relations that are obeyed. So any output compatible with this ordering is possible. In your case, this means that any outputs from 1 to 6 may happen.
Upvotes: 2