c - FlexeLint 在 va_list 上抛出错误

标签 c linux variadic-functions

为什么 FLexeLint 在下面的代码中抛出错误“警告 530:符号‘va’(第 23 行)未初始化”。

void debug(int msglevel, const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}

是否需要初始化va_list?

最佳答案

没有必要。来自man page for stdarg :

void va_start(va_list ap, last);

The va_start() macro initializes ap for subsequent use by va_arg() and va_end(), and must be called first.

此外,来自 C standard 的第 7.16.1.4 节:

2 The va_start macro shall be invoked before any access to the unnamed arguments.

3 The va_start macro initializes ap for subsequent use by the va_arg and va_end macros. Neither the va_start nor va_copy macro shall be invoked to reinitialize ap without an intervening invocation of the va_end macro for the same ap .

关于c - FlexeLint 在 va_list 上抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43832540/

相关文章:

c - 在 ubuntu 中调用 Gedit

你能解释一下 *ptr++ 和 *(++ptr) 之间的区别吗?

c++ - 将正符号变量替换为无符号变量

linux - 从 Bluez 5.48 开始如何写入特性

go - 使用gocql的cassandra查询中的可变参数

c++ - 如何将 n 个参数传递给 n 未知的函数

CC65 : Four lines bad, 两行好吗?

python - 将 Os.system 结果存储在变量中

c++ - 最后命名的参数不是函数或数组?

linux - 使用 schroot 替换 lxc