Goto prior to a variable definition - what happens with its value?

Viewed 1923

Here is some question I wondered about. Given the following code, can we be certain about its output?

void f() {
  int i = 0; 
  z: if(i == 1) goto x; else goto u; 
  int a; 
  x: if(a == 10) goto y; 
  u: a = 10; i = 1; goto z; 
  y: std::cout << "finished: " << a; 
}

Is this guaranteed to output finished: 10 according to the C++ Standard? Or can the compiler occupy the register that a is stored into, when goto to a place prior to a?

4 Answers
Related