为什么函数printk()不使用逗号分隔参数? [英] Why doesn't the function printk() use a comma to separate parameters?

查看:65
本文介绍了为什么函数printk()不使用逗号分隔参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个示例 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆