Here is a piece of code in /usr/src/linux-3.10.10-1-ARCH/include/linux/printk.h
:
static inline int printk_get_level(const char *buffer)
{
if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
switch (buffer[1]) {
case '0' ... '7':
case 'd': /* KERN_DEFAULT */
return buffer[1];
}
}
}
Is it a kind of operator? Why does "The C Programming Language" not mention it?
case '0'...'7': is case ranges Speciacation in gcc.
Range specification for case statement.
Write spaces around the ..., for otherwise it may be parsed wrong when you use it with integer values
Beware, it is not standard C and therefore not portable. It is a shorthand devised for case statements. It's well-defined since in C you can only switch on integral types.
In standard C,
...
is only used in variable length argument lists.It is gcc compiler extension allowing to combine several case statement in one line.
This is a
gcc
extension called case ranges, this is how it is explained in the document:You can find a complete list of gcc extensions here. It seems like clang also supports this to try and stay compatible with
gcc
. Using the-pedantic
flag in eithergcc
orclang
will warn you that this is non-standard, for example:It is interesting to note that Linux kernel uses a lot of gcc extensions one of the extensions not covered in the article is statement expressions.