Ah, I guess I see the problem: it doesn't really have anything to do with #pragma pack(), but with the default alignment of the 'long long' data type itself.
GCC uses a default alignment of 4 bytes for 'long long', so, if MSVC uses a default alignment of 8, that would be the problem.
You seem to be correct.
With this code:
#ifdef _MSC_VER typedef __int64 longlong_t; #else typedef __attribute__((aligned (8))) long long longlong_t; #endif
GNU C now works the same as with MSVC.
However, I think you can get GCC on i386 to use a default alignment of 8 for 8-byte sized types, by specifying the compiler option -malign-double.
Yes, that works with GNU C as well. Even without my hack above.
(Then you'll probably have to use -mpreferred-stack-boundary=3 instead of -mpreferred-stack-boundary=2 as well.)
It doesn't seem to do any difference in my simple example either with -mpreferred-stack-boundary=2 or -mpreferred-stack-boundary=3.
The only thing that matters is whether -malign-double is set.