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 = 3
和 n = 4
,但不一定如此。假设您有
int blablabla(const void *const data, const char *format, int data, ...)
然后m = 2
和n = 4
。
关于c++ - 无法理解 __attribute__ 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44954217/