Sumit Rajan wrote:
"ASobol" <so***@mccme.ru> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... //code.begin()
#include <iostream>
int g (int i)
{
static const int j = i;
return j;
}
int main (int, char**)
{
std::cout << g(0) << g(1) << g (2) << g(3);
The compiler is allowed to determine the order in which the 4 calls
to g() are executed.
Yes, but it may not execute them concurrently (unless you cannot detect
it, of course. "as if"-rule ). One call must be made first. It may be a
different choice on every run, though.
Is output of this program undefined due to C++ standart?
Undefined behaviour.
Wrong, unspecified. There are proper sequence points between the
calls, the only thing unspecified is the order of sequence points.
No variable is modified twice between sequence points. In fact,
the only variable modified is static const int j, which by
definition cannot be modified twice at all.
Regards,
Michiel Salters