Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 变量参数函数调用为宏如何定义?_C_Macros_C Preprocessor_C99 - Fatal编程技术网

C 变量参数函数调用为宏如何定义?

C 变量参数函数调用为宏如何定义?,c,macros,c-preprocessor,c99,C,Macros,C Preprocessor,C99,想象一下,我有一个调试源文件, 这是这样的: #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 DebugLogMsg1(

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

#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
DebugLogMsg1(pointer, var, pointer, 1, 2, 3);
在这种情况下,我并不真正关心函数的附加参数,但是这种情况又如何呢

#if _OWN_DEBUG_LEVEL > 0

    #undef DebugLogMsg1

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

#endif
在这种情况下,我不太确定。。。当我这样调用宏时:

#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
DebugLogMsg1(pointer, var, pointer, 1, 2, 3);

\u Expression3
是否会被视为指针1、2、3,或者确切的行为是什么?

它就是不起作用。应使用可变宏:

#define DebugLogMsg1(a, b, c, ...) DebugLogMsg(a, b, c, __VA_ARGS__)
或者更好(因为它不会引起尾随逗号的问题):


但是
\uu VA\u ARGS\uu
不是c99的东西,是吗?!还是我不明白你的例子?@Zaibis:这很像C99。刚刚打开我的ISO/IEC 9899和ctrl+f'ed的
\uu VA\u ARGS\uuuu
,但我没有找到匹配项,以前从未看到过。。。在我看来,它本身的语法更像gnu99属性。@Zaibis:再看看。6.10.3.1/2.你说得对,我找到了,但是现在我自己,6.10.3.5的分数不一样,所以我没有在我的pdf中找到匹配项。。。谢谢你,伙计。