Inside the switch statement
Ary Borenszweig
ary at esperanto.org.ar
Tue Jun 9 10:32:43 PDT 2009
Saaa wrote:
>>> What kind of fall-throughs were these?
>>>
>>> A:
>>>
>>> case value1:
>>> case value2:
>>> case valueN:
>>> code1();
>>> break;
>>>
>>> B:
>>>
>>> case value1:
>>> code1();
>>> case value2:
>>> code2();
>>> break;
>> The solution is to forbid fallthrough, and change the switch syntax:
>>
>> switch(value) {
>> case 1:
>> case 2:
>> // something
>> break;
>> }
>>
>> gives: Error, missing break at the end of case1.
>>
>> But:
>>
>> switch(value) {
>> case 1, 2:
>> // something
>> break;
>> }
>>
>> works as expected.
>>
>> What's wrong with that?
>
> Doesn't support B :)
>
> How about a warning instead?
The idea is that it not supporting B is something good.
An error is ok, and if you want to translate C code then it's really
easy to change the code to not give errors.
More information about the Digitalmars-d-learn
mailing list