C ++:空函数宏 [英] C++: Empty function macros
本文介绍了C ++:空函数宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我定义一个没有实际函数的函数宏,它是否像一个空字符串与编译器(即它不会在编译时生成任何额外的指令)?
If I define a function macro with no actual function, is it like an empty string with the compiler (i.e. It doesn't generate any extra instructions at compile time)?
示例:
#define SomeMacro(a)
SomeMacro("hello"); // This line doesn't add any instructions, does it?
推荐答案
t生成任何代码。
我看到两个地方,这是有用的。第一个是在不使用函数参数时消除警告:
I've seen two places where this is useful. The first is to eliminate warnings when a function parameter isn't used:
#define UNUSED(x)
int foo(int UNUSED(value))
{
return 42;
}
第二个是当你使用条件判断是否应该有代码
The second is when you use conditionals to determine if there should be code or not.
#ifdef LOGGING_ENABLED
#define LOG(x) log_message(x)
#else
#define LOG(x)
#endif
这篇关于C ++:空函数宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文