P99
|
◆ P99_CASERANGE
implement a range syntax for case labels. gcc has an analogous extension to the C syntax. Something like case '0'..'9': return 23;
This implementation uses macros and consequently should be more portable. switch (argv[0][0]) {
P99_CASERANGE('\0', 0): return -1;
P99_CASERANGE('0', 10): return 0;
P99_CASERANGE('A', 25): --argc;
P99_CASERANGE('.', 0): return -1;
P99_CASERANGE('a', 25, oioi): return 2;
default: return 3;
}
The additional variable argument list is optional and is used to "name" the range. This is only necessary if you have more than one P99_CASERANGE on the same logical line of code. This is intended to have the same flow control rules as if there were just one case label in front of one statement. In particular, the dependent statement may just be a |