According to C++03 Standard 1.9/5
A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible execution sequences of the corresponding instance of the abstract machine with the same program and the same input.
I don't get the "as one of" part.
If I have a specific program and a specific input and my program doesn't contain undefined behavior why would observable behavior vary? What is meant under "one of the possible execution sequences"?
In C++, certain things are left up to the implementation. For example, when you write
int x = f(a) + f(b);
The implementation may choose to call f(a) first or f(b) first.
Consider:
x = f() + g();
This allows two possible execution sequences:
__temp1 = f(); /*or*/ __temp1 = g();
__temp2 = g(); /*or*/ __temp2 = f();
x = __temp1 + __temp2; /*or*/ x = __temp2 + __temp1;
The standard does not specify which of these must be performed; just that the program must behave as if one of these two were performed. If f()
and g()
have side effects, then the program could have one of two different observable behaviours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With