Eric said:
If the feature would be so useful, why does every
example trot out 'A' ... 'Z', a useLESS construct? The
gcc documentation leads with that one and goes on to
exhibit 1 ... 5, but does not suggest a context in which
the construct would be appealing.
If someone's got an example where case ranges would
be significantly more useful and expressive, I'd be glad
to see it.
OK, let's try:
switch (cmdcode)
{case 1000..1999: filecmds(); break
case 2000..2499: editcmds(); break;
case 2500..2999: viewcmds(); break
default: misccmds();
};
But whatever example is given, someone will say it can be decomposed into a
combination of if and switch statements. Again, language minimalism for
syntax, but the runtime is some 1000 functions.
The 'A'..'Z' is perfectly OK for an ASCII machine, and there must be a
billion of those so it can be acceptable for such a 'restricted' target.
But for purists, how about a function Asc() that converts a C character code
into ASCII:
case Asc('A')..Asc('Z'): puts("This is one of ABCDEFGHIJKLMNOPQRSTUVWXYZ");
break;
The point is one can adopt any character coding inside a program, so long as
input and output are translated. So why not choose one where alphabetic
character codes are contiguous and sequential?