should this work?

Lars Ivar Igesund larsivar at igesund.net
Fri Dec 29 14:04:09 PST 2006


BCS wrote:

> void main()
> {
>    char[] str = "hello";
>    int i = 5;
>    switch(str)
>    {
>      case "hello":
>      switch(i)
>      {
>        case "goodby": // case for outer switch in inner switch
>          writef("foo\n");
>        case 1:;
>          writef("bar\n");
>      }
>    }
> }
> 
> It doesn't because (I assume), it isn't allowed to in C/C++. However
> that is because C has only one type for switches, integer. D doesn't
> have this restriction, array types are just fine. So why not (sanity
> aside*) permit it?
> 
> * I can think of no uses for it, but what does that matter.

I don't think this should be allowed. To actually enter the "goodby" case,
str will have to be changed after case "hello" has been entered.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi


More information about the Digitalmars-d-learn mailing list