This is the kind of thing that C++ is better at supporting than C. Could you consider C++ instead?
Anyhow, in C you could do this: first defined dyn_array_generic.c, etc. using the ARRAY_TYPE
in place of void*
and adding the function postfix defined in FUNC_POSTFIX
to each function name using a suitable macro, then in dyn_array.c, etc. do this:
#define ARRAY_TYPE void*
#define FUNC_POSTFIX
#include "dyn_array_generic.c"
#undef FUNC_POSTFIX
#undef ARRAY_TYPE
and in dyn_arrayi.c, etc. do this:
#define ARRAY_TYPE int
#define FUNC_POSTFIX _int
#include "dyn_array_generic.c"
#undef FUNC_POSTFIX
#undef ARRAY_TYPE
the #undef
is not strictly needed I just think it's clearer.