4 ms·
>There's no reason a C99 compiler can't do those optimizations. No, there actually is, the C standard says structs have to be laid out in memory in the same or
by PeCaN 7y ago
>There's no reason a C99 compiler can't do those optimizations.
No, there actually is, the C standard says structs have to be laid out in memory in the same order they're written and C has much weaker aliasing rules.
- pmiller2 7y agoC99 has the restrict keyword, which guarantees that the pointer won't be aliased. As far as reordering struct members, there's no reason why an implementation can't provide that as an optional optimization you must explicitly turn on. Providing such an optimization and corresponding compiler flag would not disqualify it from being a conforming implementation.
- tjalfi 7y agoThere have been compilers that did this optimization. 179.art, one of the SPEC2000 benchmarks, has some poorly laid out structs. Sun Microsystems was the first company to introduce targeted optimizations for this benchmark. GCC also had an optimization pass[0] for this. It may have been removed. [0] https://www.research.ibm.com/haifa/dept/_svt/papers/golovanevsky.pdf https://www.research.ibm.com/haifa/dept/_svt/papers/golovane...