
On 17 June 2013 22:30, Daryle Walker wrote:
If you don't mind, why do you want to do pack structs in the first place? Most people cringe at the thought of packing-specific code.
I've read about using an array segment of complex numbers as an array of real numbers (but twice as long) for stuff like Fourier transforms. At http://en.cppreference.com/w/cpp/numeric/complex#Non-static_data_members, the effect is documented for std::complex (at least for float/double/long-double). I want to simulate the effect.
template < typename T, unsigned R > struct complex_it { T c[ 1ULL << R ]; };
The above class template will be standard-layout if "T" is; that mandates no starting padding. Array elements are packed. So I can do the array-segment translation only if there's no trailing padding. In contrast:
template < typename T, unsigned R > struct complex_rt;
template < typename T > struct complex_rt
{ T r; }; template < typename T, unsigned R > struct complex_rt { complex_rt
b[2]; }; will have padding all over the place if there's any trailing padding at a lower level.
But why would it have padding at a lower level?
On a sane implementation complex_rt