Is it possible to iterate of a C struct, where all members are of same type, using a pointer. Here\'s some sample code that does not compile:
#include
You can also use an unnamed union/struct:
struct foo {
union {
struct {
int mem1;
int mem2;
int mem3;
int mem4;
};
int elements[4];
};
};
foo thefoo;
for (int i = 0; i < 4; ++i) {
thefoo.elements[i] = i;
}
This might not work on some compilers, int this case you'll have to explicitily name the union and struct inside foo
,