No more fall through in case statement?
James Dennett
jdennett at acm.org
Fri Jan 4 14:33:58 PST 2008
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.)
-- James
More information about the Digitalmars-d
mailing list