Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom type with va_arg

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?

like image 326
Edwin Skeevers Avatar asked Mar 08 '26 13:03

Edwin Skeevers


1 Answers

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

like image 89
dbush Avatar answered Mar 10 '26 03:03

dbush