The new C ++ 11 specification also has a new feature , although I do not believe that many vendors are already implemented.
You can try the package pragma, although it is not supported by the specification. Both GCC and MS support this, though.
This aligns the structure at 1 byte boundaries, although you can change the number to whatever you want.
#pragma pack(push,1) // ... #pragma pack(pop)
update:
Thus, it is obvious that the foregoing will not work, since it only reduces the filling, never expanding it. Unfortunately, today I do not have a test environment.
Perhaps using an anonymous union will work. I know that it will expand to the largest size, although I do not know if you will receive any guarantees regarding alignment otherwise.
template<typename T, size_t padding_size> struct padded_field { union { T value; uint8_t padding[padding_size]; }; };
Tom kerr
source share