gpt4 book ai didi

c - #define 语法是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 15:46:09 24 4
gpt4 key购买 nike

我碰到这个,不懂。

#define IDEBUG(a...)  

“(a...)”是什么意思?

最佳答案

那是一个 variadic macro .

从链接页面逐字引用:

A macro can be declared to accept a variable number of arguments much as a function can. The syntax for defining the macro is similar to that of a function. Here is an example:

 #define eprintf(...) fprintf (stderr, __VA_ARGS__)

This kind of macro is called variadic. When the macro is invoked, all the tokens in its argument list after the last named argument (this macro has none), including any commas, become the variable argument. This sequence of tokens replaces the identifier VA_ARGS in the macro body wherever it appears. Thus, we have this expansion:

 eprintf ("%s:%d: ", input_file, lineno)
==> fprintf (stderr, "%s:%d: ", input_file, lineno)

对于那个特定的表格,在页面的下方进一步引用:

If your macro is complicated, you may want a more descriptive name for the variable argument than __VA_ARGS__. CPP permits this, as an extension. You may write an argument name immediately before the `...'; that name is used for the variable argument. The eprintf macro above could be written

#define eprintf(args...) fprintf (stderr, args)

关于c - #define 语法是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9031728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com