Problems caused by insufficient memory alignment can often seem to appear at random, since things can be correctly aligned by coincidence until you change something unrelated. Is there a compiler flag or some other way to bring all of these problems out of hiding? I'd want it to make sure that types are never more aligned than they have to be. For example, on x86, the address of char
s would always be odd, and the address of int
s would always be ≡ 4 (mod 8). (Obviously, this would waste memory and probably make the program slower too, so it's not something I'd leave enabled in a release build.)
Edit: For clarification, this should only affect the starting addresses of arrays and struct
s, not their internal layouts (the latter would break compatibility with basically everything, which I definitely don't want).