-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example where sizeof differs between clang and gcc #6009
Comments
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: 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: 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. |
Rename test
Extended Description
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;
}
The text was updated successfully, but these errors were encountered: