title: C compiler structure optimisation
body: <p>The C standard does not allow certain optimisations of structures: for example, rearrangement of fields, merging fields, discarding fields that are never read from, hoisting fields out of the structure if they can be turned into auto variables, etc. This is needed for various reasons, including consistent structure layouts across compilation units and allowing cast-compatible structures.</p>
  
  <p>Do any modern compilers (e.g. gcc, clang, Visual C) support extensions that allow me to tell it that it <em>is</em> okay to do these optimisations?</p>
  
  <p>Naturally, they'd only make sense for definitions that were local to a single compilation unit, so that the compiler could see all possible uses of the structure; and certain things (like the aforesaid cast-compatible structure definitions) would become unusable. But for certain tasks this could be a very valuable optimisation.</p>
  
  <p>I do know that gcc <em>used</em> to have a <code>-fipa-struct-reorg</code> option to allow precisely this, but it never worked very well and bit rotted, and was eventually taken out. But I don't know if it's been replaced by anything. And I haven't been able to find anything in clang, which surprises me because I would think that this is precisely the kind of optimisation that clang would be all over...</p>