3 ms·
Years ago I worked on a few projects that used complicated structure ordering, but even then it was my understanding that (with the right options) compilers cou
by jobu 12y ago
Years ago I worked on a few projects that used complicated structure ordering, but even then it was my understanding that (with the right options) compilers could optimize these things better than most people could by hand.
- pcmonk 12y agoThis is something the compiler can't optimize very well. For one thing, the spec requires that they appear in the given order. If this wasn't the case, a significant amount of code would break. I've seen a good bit of code where there's a struct A, and then struct B begins with the same fields as in struct A. This allows you to treat either of them as a struct A, a kind of polymorphism. The compiler doesn't know whether you're going to do that, so it can't arbitrarily rearrange the members of the structs.