, - , " " , , , . , , , .
, , .
C
:
struct X{};
struct Y{};
struct Z {
struct X x;
struct Y y;
int i;
};
Z POD ++ 03, C, x y . C POD. , C , POD ++ 03, :). , C . . , - .
, , , , y , x, - 5.10/2. , , .
IMO, .
, :
struct Z1 {
struct X x[1];
struct Y y[1];
int i;
};
... , sizeof(Z1) == sizeof(Z) x y do (.. , ). .
,
, . , , " ", .. . , Stroustrup ++ - .
, , , typedefs ..; , , , , .
- Allocator STL - , , " ", .
... , . , . , , , .
There are many subtle things that do not work with this optimization. For example, you cannot memcpybits of a POD object of size zero into an array char, and then backward or between subobjects of size zero. I have seen people inject operator=using memcpy(I donβt know why ...) that would break such things. Presumably, this is less of a problem to break up such things for base classes instead of members.