« Automata | Main | Involuntary Reboot Log #16 »
September 24, 2007
Things you learn from looking at the HexFiend source code
static BOOL isHex(unichar c) {
switch (c) {
case '0' ... '9':
case 'a' ... 'f':
case 'A' ... 'F':
return YES;
default: return NO;
}
}
Well that one is an eye-opener. I have often wished for the "range" shorthand provided here by the ... (three dots) operator. The thing is, I'd never seen this operator in C code before and my trusty C Pocket Reference only makes one mention of the operator as an "optional argument indicator". In its section on case labels it only says:
Every case label has the form case const:; where const is a constant integer expression.
How could I have missed such a useful thing? The Wikipedia page on page on C and C++ operators makes no reference to it, nor does the main article on C.
The 550-page C99 standard only makes references to ... as the "ellipsis punctuator" and describes how it is used to indicate an unspecified number of additional arguments.
Finally I found the answer: it's a GNU GCC extension. As noted by the documentation:
Write spaces around the ..., for otherwise it may be parsed wrong when you use it with integer values.
Very useful indeed.
More Development articles
Posted by wincent at September 24, 2007 11:59 AM


