What is the use case for this weird switch mecanism

Daniel Murphy yebblies at nospamgmail.com
Tue Oct 30 16:31:41 PDT 2012


"deadalnix" <deadalnix at gmail.com> wrote in message 
news:k6ouhh$116v$1 at digitalmars.com...
> Today, I noticed by digging into D details the following construct :
>
> [snip switch being stupid]
>
> What the hell statement is supposed to do ? And what is the use case for 
> this ?

The structure for switch is:
switch(value) Statement(s)

There is very little structure imposed on the statements it contains.  If 
there are any case or default labels inside the switch that are not inside 
another inner switch, they are linked to the value and can be jumped to.

One (the only?) use case for the loose definition is Duff's Device.

The reason it's like this in D: that's how it is in C. 




More information about the Digitalmars-d mailing list