为什么一个人需要两个方括号才能在C中使用宏? [英] Why one needs two brackets to use macros in C?

查看:70
本文介绍了为什么一个人需要两个方括号才能在C中使用宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    KdPrint(("Enter HelloWDMAddDevice\n"));

这样做的原因是什么?

推荐答案

因此,您可以将整个参数列表传递给宏,然后将其传递给带有可变数量参数的函数.

That is so you can pass an entire argument list to the macro and have it pass it on to a function that takes a variable number of arguments.

我敢打赌该宏的定义是:

I would bet anything that the definition of that macro is:

#if DEBUG /* or something like it */
#define KdPrint(args) (printf args)
#else
#define KdPrint(args) /* empty */
#endif

或与其他功能类似,类似于printf.

Or similar to some other function that works just like printf.

如果将其定义为printf(args),则只能传递单个字符串参数,因为宏的参数不能包含不在嵌套括号内的逗号.

If it were defined as printf(args), then you could only pass the single string argument, because an argument to a macro can't contain a comma that isn't inside a nested parenthesis.

这篇关于为什么一个人需要两个方括号才能在C中使用宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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