News for hackers. Stuff that matters.
Re:The Lost Art of C Structure Packing (2014) by superuser2 on Friday August 05, 2016 @02:58PM (#12234927)
Structs get written directly to disk and network. Copies of the same program would produce different output depending on the optimization strategy they were compiled with. That's vigorously not allowed.
Re:The Lost Art of C Structure Packing (2014) by kazinator on Friday August 05, 2016 @04:52PM (#12235671)
Also, the translation unit compilation model of C would be troublesome here, if optimization settings could influence struct layout. You can't have different translation units interpreting the same struct type declaration differently.
Re:The Lost Art of C Structure Packing (2014) by maccard on Friday August 05, 2016 @06:52PM (#12236223)
> You can't have different translation units interpreting the same struct type declaration differently.

Sure you can!

    // MyHeader.h  
    struct MyStruct {  
    int A;  
    char b;  
    int* c;  
    };

    // A.cpp  
    #include "MyHeader.h"

    <...>

    // B.cpp  
    #pragma pack(push, 16)  
    #include "MyHeader.h"  
    #pragma pack(pop)

    <...>