Is there any way to loop through a struct with elements of different types in C?
I’m not sure what you want to achieve, but you can use X-Macros and have the preprocessor doing the iteration over all the fields of a structure: //— first describe the structure, the fields, their types and how to print them #define X_FIELDS \ X(int, field1, “%d”) \ X(int, field2, “%d”) \ X(char, field3, “%c”) … Read more