mystruct_t v = va_arg(a_list, mystruct_t);
就 C 规范而言,这可以吗(使用大于等于 int 大小的自定义数据类型)?
最佳答案
C 标准中没有关于将结构类型用作可变参数的限制。所以你想做的事是允许的。
唯一不允许作为可变参数的参数类型是那些会进行提升的参数类型,即小于 int
的整数类型(signed 或 unsigned char
或 short
或等效项)以及 float
。
作为引用,C standard 的第 7.16.1.1p2 节关于 va_arg
状态:
The parameter type shall be a type name specified such that the type of a pointer to an object that has the specified type can be obtained simply by postfixing a
*
to type. If there is no actual next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined
关于c - 使用带有 va_arg 的自定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74857961/