Is it legal to use the address of the first member of a struct and use it like an array to access the different members?
Like:
struct Foo {
int a, b, c;
}
Can I do
Foo f = {1, 2, 3};
int *fPtr = &f.a;
int res = fPtr[1]; // access to b
?
Or is it undefined behavior?
And is it equivalent to:
Foo f = {1, 2, 3};
int *fPtr = reinterpret_cast<int *>(f);
int res = fPtr[1];
?
And is this one undefined behavior?