Goto skips declaration
Bauss
jj_1337 at live.dk
Tue Oct 30 06:37:22 UTC 2018
On Monday, 29 October 2018 at 03:24:35 UTC, rikki cattermole
wrote:
> On 29/10/2018 4:22 PM, Michelle Long wrote:
>> This should not be an error when the goto jumps outside the
>> current block!
>>
>> {
>> goto Y;
>> int x;
>> }
>> Y:
>>
>> There is no chance of any local variable being used. This
>> makes it impossible to use goto statements in any reasonable
>> way without littering the code with brackets.
>>
>
> Compiles + runs:
>
> import std.stdio;
>
> void main() {
> {
> goto Y;
> int x;
> writeln("booo", x);
> }
> Y:
> writeln("Hello D");
> }
>
> Going to need a more complete example.
The problem is when you remove the brackets.
@OP
I don't see what you expect the compiler to do? You're skipping
the declaration and usage of it so what's the point?
D is not Javascript and has no concept of hoisting.
More information about the Digitalmars-d
mailing list