Reputation: 319
mystruct_t v = va_arg(a_list, mystruct_t);
Is this okay (using a custom data type that's >= the size of an int) as far as C specs go?
Upvotes: 3
Views: 209
Reputation: 224522
There is no restriction in the C standard regarding the use of a struct type as a variadic argument. So what you're looking to do is allowed.
The only argument types that are not allowed as variadic arguments are those that would undergo promotion, i.e. integer types smaller than int
(signed or unsigned char
or short
or equivalent) as well as float
.
For reference, section 7.16.1.1p2 of the C standard regarding va_arg
states:
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
Upvotes: 2