c++ - 无法理解 __attribute__ 标签

标签 c++ gcc

extern "C" int asnprintf (char **ret, size_t max_sz, const char *format, ...)
    __attribute__ ((format (printf, 3, 4)));

在阅读 nmap 的源代码时,我遇到了这个函数声明,但我在理解它时遇到了困难。

这就是 this webpage对此说道:

基于

__attribute__((format(printf, m, n)));

The (m) is the number of the "format string" parameter, and (n) is the number of the first variadic parameter.

我不明白他说的“格式字符串”指的是什么;它们只是影响函数行为的参数吗?

另外,第一个可变参数的编号是多少?在我见过的所有例子中,它总是比m多1,这总是正确的吗?你能举一个实际的例子吗?

谢谢。

最佳答案

extern "C" int asnprintf (char **ret, size_t max_sz, const char *format, ...)
                               ^1              ^2               ^3        ^4

I don't understand what is he refering to when saying "format string"; are they just the arguments which affects the behaviour of the function?

格式字符串是您通常在 printf 中找到的格式字符串,例如 "%0.3f %s" ecc。当然,该函数将采取相应的行动。

Also, what is the number of the first variadic parameter? In all the examples I have seen it is always one more than m, is this always true? Could you give a practical example where is not?

在这种情况下,m = 3n = 4,但不一定如此。假设您有

int blablabla(const void *const data, const char *format, int data, ...)

然后m = 2n = 4

关于c++ - 无法理解 __attribute__ 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44954217/

相关文章:

c++ - 多个网格到单个波前 OBJ 文件

c++ - 如何在macOS终端上执行Qt应用程序?

c - 在与原子加载和存储同步的线程之间共享变量是否安全?

GCC 中的优化

c - GCC 中的简单错误陷阱

c++ - 如何初始化和填充 vector<vector<int>> 类型的 vector ?

c++ - 没有名为 'argument_type' 的类型

c++ - extern “C”在C++中有什么作用?

c++ - 在 xcode 中设置 C++ 编译标志

python - 为 python setup.py 安装指定头文件位置