compile time assertions *across modules* / c,c++
<p>recently i discovered in a relatively large project, that ugly runtime crashes occurred because various headers were included in different order in different cpp files.</p>

<p>These headers included #pragma pack - and these pragmas were sometimes not 'closed' ( i mean, set back to the compiler default #pragma pack() ) - resulting in different object layouts in different object files. No wonder the application crashed when it accessed struct members being created in one module and passed to another module. Or derived classes accessing members from base classes.</p>

<p>Since i like the idea  to create a more general debugging and assertion strategy from every bug i find, i would really like to assert that object layouts are always and everywhere the same.</p>

<p>So it would be easy to assert </p>

<p>ASSERT( offsetof(membervar) == 4 )</p>

<p>But this would not catch a different layout in another module - or require manual updates whenever the struct layout changes .. so my favourite idea would be something like</p>

<p>ASSERT( offsetof(membervar) == offsetof(othermodule_membervar) )</p>

<p>Would this be possible with an assertion? Or is this a case for a unit test?</p>

<p>Thanks,
H</p>
