elBradford elBradford - 1 year ago 63
Linux Question

Why doesn't the function printk() use a comma to separate parameters?

An example


printk(KERN_INFO "Log message.\n");

Perhaps this question is more about C in general, because I've never seen a function in C before that separated parameters without a comma.

How does this work? What does the compiler do with this information? Since the log level is an integer and the message is a pointer to a char array, it must pass them separately.

Answer Source

The printk() function only takes one const char* argument. The KERN_INFO macro expands to "\001" "6", yielding:

printk("\001" "6" "Log message.\n");

The C lexer concatenates adjacent string literal tokens which means that the above is converted into:

printk("\0016Log message.\n");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download