如何不变量参数Functioncall宏观界定? [英] How to does a variable argument Functioncall as macro define?

查看:193
本文介绍了如何不变量参数Functioncall宏观界定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有一个调试的源文件,
这是这样的:

Imagine, I have a debug source file, which is like this:

#if _OWN_DEBUG_LEVEL != 0

    void DebugLogMsg (DebugStruct_t *DebugStruct, size_t sizeID, char const *szFormat, ...);

#else

    #define DebugLogMsg(_Expression1, _Expression2, _Expression3) ((void)0) 

#endif

在这种情况下,我真的不关心其他参数的功能,但对于这种情况?

In this case I do not really care about the additional arguments to the function, but what about this case?

#if _OWN_DEBUG_LEVEL > 0

    #undef DebugLogMsg1

    #define DebugLogMsg1(_Expression1, _Expression2, _Expression3) \ 
        DebugLogMsg(_Expression1, _Expression2, _Expression3)

#endif

在这种情况下,我不太清楚...当我调用宏是这样的:

In this case I'm not quite sure... when I call the macro like this:

DebugLogMsg1(pointer, var, pointer, 1, 2, 3);

_ex pression3 是请客的那会是指针,1,2,3 还是什么将是确切的行为?

will _Expression3 be treat as would it be pointer, 1, 2, 3 or what would be the exact behaviour?

推荐答案

这是做不到的。您应该使用复杂的宏:

It just wouldn't work. You should use variadic macros:

#define DebugLogMsg1(a, b, c, ...) DebugLogMsg(a, b, c, __VA_ARGS__)

或许更好(因为它不会导致尾随逗号的问题):

Or perhaps better (since it doesn't cause issues with trailing commas):

#define DebugLogMsg1(...) DebugLogMsg(__VA_ARGS__)

这篇关于如何不变量参数Functioncall宏观界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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