为什么函数printk()不使用逗号分隔参数? [英] Why doesn't the function printk() use a comma to separate parameters?
问题描述
一个示例 printk
调用:
printk(KERN_INFO "Log message.\n");
也许这个问题通常与C有关,因为在用逗号分隔参数之前,我从未见过C中的函数.
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.
这是如何工作的?编译器如何处理此信息?由于日志级别是整数,并且消息是指向char数组的指针,因此必须分别传递它们.
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.
推荐答案
printk()
函数仅采用一个 const char *
参数. KERN_INFO
宏扩展为"\ 001""6"
,产生:
The printk()
function only takes one const char*
argument. The KERN_INFO
macro expands to "\001" "6"
, yielding:
printk("\001" "6" "Log message.\n");
C词法分析器连接相邻的字符串文字标记,这意味着上面的内容转换为:
The C lexer concatenates adjacent string literal tokens which means that the above is converted into:
printk("\0016Log message.\n");
这篇关于为什么函数printk()不使用逗号分隔参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!