P99

◆ P99_CASERANGE

#define P99_CASERANGE (   START,
  LEN,
  ... 
)

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;
}
Parameters
STARTmust evaluate to an expression that can be used as a case label
LENmust evaluate to a decimal number. If this is 0 the depending statement will never be reached as a direct jump to the "label". Depending on the flow for the other cases the statement may or may not be reachable when falling through from a previous case. In the example above, for the first range '\0' is not reachable. But the range for '.' is reachable after the execution of the range starting with 'A'.

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 break to break out of the enclosing switch.

Definition at line 1037 of file p99_for.h.

P99_CASERANGE
#define P99_CASERANGE(START, LEN,...)
implement a range syntax for case labels.
Definition: p99_for.h:1037