In my mind, always, definition means storage allocation.
In the following code, int i
allocates a 4-byte (typically) storage on program stack and bind
The position of the declaration of i
is irrelevant to the compiler. You can prove this to yourself by compiling your code with int i
before the goto
and then after and comparing the generated assembly:
g++ -S test_with_i_before_goto.cpp -o test1.asm
g++ -S test_with_i_after_goto.cpp -o test2.asm
diff -u test1.asm test2.asm
The only difference in this case is the source file name (.file
) reference.
In my mind, always, definition means storage allocation.
This is not correct. The storage for the variable is reserved by the compiler when it creates the stack-layout for the function. The goto
just bypasses the initialization. Since you assign a value before printing, everything is fine.