Hi all,
I'm wondering about the layout of a class, and what guarantees the standard (C++03) gives about class member layouts.
For instance, if I have a class like:
and I have a binary packet with the same layout as above arriving (how it arrives is irrelevant in my case) in a buffer, is the following guaranteed to work:Code:struct Header { u_char name; u_char val; u_char other; u_char whatever; u_char etc; };
In other words, is a compiler *never* allowed to alter the layout of the class? AFAICT, if it's a POD type - which I understand means it has only a default constructor - it can't be reorganised, but what if I want a more complex constructor?Code:Header hdr; read( reinterpret_cast<u_char*>(hdr) ); // Everything in it's right place now
I'd appreciate any advice/pointers to the right part of the standard.



LinkBack URL
About LinkBacks




CornedBee