I was wondering if it is possible in C to get the type from an element in an array. I have the following code, where you have to manually specify the type, but would like to remove the second argument.
#define ForEach( func, type, list)do {\
int num_elements = sizeof(list) / sizeof(type);\
int iter;\
for( iter = 0; iter < num_elements; iter++)\
func(list[iter]);\
}while(0)
void display(int n) {
printf("\n%d\n", n);
}
int main(void){
int list [] = { 1,2,3,4,5,6,7,8,9,10};
ForEach(display, int, list);
return 0;
}