Here's a reason I didn't see so far - without standard rearrangement rules, it would break compatibility between source files.
Suppose a struct is defined in a header file, and used in two files.
Both files are compiled separately, and later linked. Compilation may be at different times (maybe you touched just one, so it had to be recompiled), possibly on different computers (if the files are on a network drive) or even different compiler versions.
If at one time, the compiler would decide to reorder, and at another it won't, the two files won't agree on where the fields are.
As an example, think of the stat
system call and struct stat
.
When you install Linux (for example), you get libC, which includes stat
, which was compiled by someone sometime.
You then compile an application with your compiler, with your optimization flags, and expect both to agree on the struct's layout.