You can do it with macros. It's definitely not pretty, but it is highly compatible (works in C, C++03, etc.):
In header file args.h
:
#define ARGS_STRUCT ARG(int, arg1) SEP ARG(char *, arg2) SEP ARG(void *, arg3)
#undef ARG
#undef SEP
You can declare the struct as
struct Args {
#define ARG(type, name) type name
#define SEP ;
#include "args.h"
};
and the function as
int func(
#define ARG(type, name) type name
#define SEP ,
#include "args.h"
);
initialize the struct with
struct Args args = {
#define ARG(type, name) name
#define SEP ,
#include "args.h"
};
pass in args with
struct Args args;
func(
#define ARG(type, name) args.name
#define SEP ,
#include "args.h"
);
Tested, no problems with Clang and Clang++ (both 6.1).