I have this sample code where I pass the number of parameters in count followed by different type arguments.
struct my_struct;
my_func(int count, char* input_1, my_struct input_2, my_struct input_3);
my_func(int count, char* input_1, my_struct input_2);
How can I retrieve arguments? I Know using va_arg gives the argument for primary data types, but structs are not accepting.
Passing a non-POD type as a variadic parameter is non-portable. I believe it will work (with warnings) in MSVC, while clang will outright refuse to compile it. In other cases it may compile (hopefully with warnings), but not execute in the way you might expect.
You can instead pass the variadic parameters as pointers then in the function:
// Get copy
my_struct input = *va_arg( vl, my_struct* ) ;
or
// Get reference
my_struct* input = va_arg( vl, my_struct* ) ;
The call might then look like:
my_struct a ;
my_struct b ;
...
my_func( 2, str, &a, &b ) ;