J
Julian Mensch
Hi,
In C++, the following code compiles without error:
void main()
{
goto TestLabel;
if (true) {
TestLabel:;
}
}
However, in C# the equivalent code produces an error:
No such label 'TestLabel' within the scope of the goto statement
And a warning:
This label has not been referenced
----
It sounds like the label identifier has a scope that's local to
whatever
set of curly braces it's currently inside, rather than the function
body.
I can understand not letting someone jump in and out of, say, a
"using"
block or a try/catch/finally construct, but this has me baffled. Can
anyone explain to me in language theory terms what's happening here,
or point me to the MSDN pages that describe the scope of labels and
how to create a label with a greater scope that the top of the
compiler's
scope stack? Coming to C# from C++, this has me very confused.
Best regards,
-- Julian Mensch
In C++, the following code compiles without error:
void main()
{
goto TestLabel;
if (true) {
TestLabel:;
}
}
However, in C# the equivalent code produces an error:
No such label 'TestLabel' within the scope of the goto statement
And a warning:
This label has not been referenced
----
It sounds like the label identifier has a scope that's local to
whatever
set of curly braces it's currently inside, rather than the function
body.
I can understand not letting someone jump in and out of, say, a
"using"
block or a try/catch/finally construct, but this has me baffled. Can
anyone explain to me in language theory terms what's happening here,
or point me to the MSDN pages that describe the scope of labels and
how to create a label with a greater scope that the top of the
compiler's
scope stack? Coming to C# from C++, this has me very confused.
Best regards,
-- Julian Mensch