
2 Aug
2012
2 Aug
'12
5:40 p.m.
On Thursday 02 August 2012 01:28:12 Daniel Larimer wrote:
Suppose I did this:
template<typename T, unsigned int S, typename A = double> struct fwd { ... union { A _force_align; char s[S]; } _store; };
Now users of the API could 'align to' any type they wish, defaulting to double which should be sufficient for most cases. Anyone using forward declarations like this is probably doing so for types that are at least 8 bytes in size and probably not for types leveraging SSE vectors.
I think, specifying an integral alignment would be better for this very reason. However, you will probably have to resort to compiler-specific directives to achieve alignments greater than ones for the standard types.