gpt4 book ai didi

c++ - 无法理解 __attribute__ 标签

转载 作者:搜寻专家 更新时间:2023-10-31 02:10:36 25 4
gpt4 key购买 nike

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/

25 4 0