Is this legal in C?
struct Doubles
{
double a,b,c;
};
void foo(struct Doubles* bar)
{
double* baz = (double*)bar;
baz[0]++;
baz[1]++;
baz[2]++;
}
I know that it "works" on MSVC 2010, but I don't know if it's legal, or if different layouts could cause UB.
This leads to undefined behaviour. The layout of the struct is not totally prescribed by the standard. For instance, there may be padding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With