On 2016-09-26 16:31, Nick Sabalausky wrote:

Really? I may have to look into this more then.

Yes, try compiling it next time ;)

Hmm, well for starters, according to
<http://dlang.org/spec/statement.html#GotoStatement>:
"It is illegal for a GotoStatement to be used to skip initializations."

Although if that's true, I don't know why that example compiled. Maybe
because "foo" wasn't used from "case 2:" onward? Maybe it failed to
notice the initialization since it was in an if condition? Or maybe the
compiler forgot to implement the same "can't skip initialization" check
for switch/case?

It's a bug [1]. But it seems that if State is replaced with a plain int, the compiler will initialize the variable, even if it's later jumped over. So I assume, that when it works as it supposed to, it will be possible to jump like in C, but the compiler will still initialize the variables.

[1] https://issues.dlang.org/show_bug.cgi?id=16549

--
/Jacob Carlborg

Reply via email to