Clang outputs 72 and gcc 80 on my x86-64 linux box. What's going on here is that gcc does not round up the size of the type UINT192 to the alignment the user specified, but it does use this alignment to round up the size of the array of UINT192. I asked on #gcc whether this should be considered a gcc bug, but richi thought it was "by design". #include <stdio.h> typedef __attribute__((aligned(16))) struct { unsigned long long w[3]; } UINT192; UINT192 ten2mk192M[] = { {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}, {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}, {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}} }; int main(void) { printf("sizeof: %lu\n", sizeof(ten2mk192M)); return 0; }
I'm not so sure that this is a clang bug. I can't find any mention in the standards about padding in arrays. C++ 5.3.3p2 (expr.sizeof) says: "When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element." C99 6.5.3.4p6 (sizeof) implies the same with "Another use of the sizeof operator is to compute the number of elements in an array: sizeof array / sizeof array[0]" Note that in both standards, in those sections they specifically mention padding for classes/structures. You lose the symmetry in multidimensional arrays: sizeof(UINT192[2][3]) == 160 sizeof(UINT192[3][2]) == 144 Could someone let me know what is the justification for the padding in the array ?
Submitted http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47557 to get input from gcc developers.
Reverified, amusingly llvm-gcc ICE's on this.
Dragonegg doesn't though :)
Fixed at r130242.