On 1/24/13, Brian Duffy <[email protected]> wrote:
> On Thu, Jan 24, 2013 at 2:34 PM, Flemming Richter Mikkelsen <
> [email protected]> wrote:
>> Hello.
>>
>> I am new to this list. Please let me know if I post in the wrong place.
>>
>> A long time ago I tried case fallthrough in Vala.
>> It didn't work as in C, so I wrote that special code in C and the rest in
>> Vala.
>>
>> In stead of forbidding case fallthrough all together, I believe a good
>> compromise would be to implement a new keyword, nobreak, solely for this
>> purpose.
>>
>> Any ideas?
> Can't you use an "if ... else if" structure to accomplish this behavior?
Sure... but then again you can use «if .. else if» instead of switch
in all cases.
This doesn't mean switch statements are useless.
Example of the requested idea:
typedef enum state {
E_UNINITIALIZED,
E_NOT_POPULATED,
E_POPULATED,
} state_t;
extern state_t myLongVariableName[];
// my suggestion:
switch (myLongVariableName[i]) {
case E_UNINITIALIZED:
init();
nobreak;
case E_NOT_POPULATED:
populate();
nobreak;
case E_POPULATED:
analyze();
break;
default:
// throw an index out of range exception
}
// the C style:
switch (myLongVariableName[i]) {
case E_UNINITIALIZED:
init();
case E_NOT_POPULATED:
populate();
case E_POPULATED:
analyze();
break;
default:
fprintf(stderr, "Index %d out of bounds for
myLongVariableName[%d]\n", myLongVariableName[i], i);
assert(0);
}
// the current Vala style:
switch (myLongVariableName[i]) {
case E_UNINITIALIZED:
init();
populate();
analyze();
break;
case E_NOT_POPULATED:
populate();
analyze();
break;
case E_POPULATED:
analyze();
break;
default:
// throw an index out of range exception
}
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list