Senua
Senua

Reputation: 586

"goto" behavior in C : how symbols are handled?

I was wondering, in the following code :

{
    int i = 42;
    goto end;
}
end:

What is the status of the symbol i when we reach end: (what would we see in a debugger) ? Does it still exist, even if we're out of the scope ? Is there a standard behavior or is it compiler-dependent ?

For the sake of the example, let's assume that the code is compiled using gcc with debug symbols.

Subsidiarily, is the behavior the same in C++ ?

Thank you.

Upvotes: 3

Views: 174

Answers (2)

i486
i486

Reputation: 6570

The status is... invisible (out of scope).

Upvotes: 3

Guy haimovitz
Guy haimovitz

Reputation: 1625

A variable that has been declared in a block will "live" only in that block (it does not matter if you used goto or not).

This behavior is the same in c++

Upvotes: 8

Related Questions