si Guglielmo lo avevo visto : ho chiesto qui perchè quanto riguarda opzioni multiple non viene data nessuna info... quindi allo stesso modo potevo presupporre che potesse esserci anche una "feature non documentata" relativa a maggiore minore uguale etc ...
lì dice When a case statement is found whose value matches that of the variable, the code in that case statement is run. e non altro ...
forse da buon italiano presuppongo che ciò che non è scritto in una norma è possibile ... e non il contrario
Le opzioni multiple sono semplicemente una serie di statement "case" consecuitivi, quindi ... rispettano la sintassi ...
switch (variabile) {
case 1:
case 2:
case 3:
// fanno tutte e tre la stessa cosa che metti qui
break;
case 7:
case 8:
// fanno tutti e due la stessa cosa che metti qui
break;
case 100:
// valido solo per il valore 100
break;
default:
// valori diversi
break;
}
Concordo al 100% ... credo che GCC accetti quella sintassi, ma dato che NON è nello standard, va evitata o ... se poi ti sposti di piattaforma rischi di buttare il tutto ...
The switch statement is a multi-way decision that tests whether an expression matches one of a number of constant integer values, and branches accordingly.
switch (expression) {
case const-expr: statements
case const-expr: statements
default: statements
}
Each case is labeled by one or more integer-valued constants or constant expressions. If a case matches the expression value, execution starts at that case. All case expressions must be different. The case labeled default is executed if none of the other cases are satisfied. A default is optional; if it isn't there and if none of the cases match, no action at all takes place. Cases and the default clause can occur in any order.
Notare che è ovviamente ammessa anche una forma del genere:
switch (v) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ndigit[c-'0']++;
break;
...