I'm trying to write a function taking as a parameter a buffer (void *), the type size, the type name and the number of elements. The buffer may contain values of a limited number of basic types (int, float, double, ...). Within this function, I would like to be able to, let's say, increment each value. It looks like that :
void increment (void *buffer, int type_size, char *type_name, int n_elements)
{
for (int i=0; i<n_elements; i++)
((MACRO(type_name))(buffer))[i]++; // ???
return;
}
My question is as simple as: how can I "dynamically" cast my buffer? I can add more function parameters if needed. Maybe something can be done using macros but I can't figure this out.