No more fall through in case statement?
Bill Baxter
dnewsgroup at billbaxter.com
Fri Jan 4 19:00:58 PST 2008
James Dennett wrote:
> bearophile wrote:
>> Bill Baxter:
>>> I'm no C# guy but that looks like a nice way to fix C's switch.
>> I think the C switch is broken in 2 or more ways, so I'd like to see D improve it. This is some code I have shown time ago:
>>
>> import std.stdio: writefln;
>> void main(string[] args) {
>> switch (args[1]) {
>> int x = 1; // NOT initialized?
>> case "1": writefln("1! x=", x); break;
>> case "2": writefln("2! x=", x); break;
>> }
>> }
>
> C++ fixed this some time in the last century, making the code
> above ill-formed (diagnostic required) as it skips the initialization
> of x.
>
> (It's still UB in C99 so far as I know.)
That's actually in the spec? Cool. I thought it was just a QOI thing.
--bb
More information about the Digitalmars-d
mailing list