> Perhaps a better fix is this: > > struct Mem { > i64 i; > double r; > char *z; > int n; > u16 flags; > u8 type; > u8 enc; > void (*xDel)(void *); > union { > long double notUsed1; > char zShort[NBFS]; > }; > }; > > The compiler would then (hopefully) insert an appropriate > amount of padding prior to zShort so that it had the same > alignment restructions as a long double. > > This approach uses an anonymous union, which I confess is > a C construct that I have never in 22 years of C programming > had the occasion to employ. It seems to work well enough > using gcc 3.3.4. But down in my gut I have this nagging > fealing that it will likely break on some compilers. >
Well, it's supported by most compilers today, but I try to avoid anonymous unions in C code as well. They are fairly standard for C++, but not for C. But the approach seems fine to me - the alignment will be forced in this case.