It depends on the compiler and its default settings. In fact, Visual C++ 2003 and Visual C++ 2005 do not do what you just assumed.
Returns 2 bytes budCode:#include <iostream> #include <string> struct Actor { unsigned short int a; }; int main() { std::cout << sizeof(Actor) << std::endl; system("pause"); return 0; }
I would suggest that you read the docs a little more carefully. It will become your best friend.
In most cases, just go to Project - Properties - C/C++ - Code Generation - Struct Member Alignment
In code, you can do this...
During runtime, sizeof(Actor) returns 32.Code:#define ALIGN32 __declspec(align(32)) ALIGN32 struct Actor { unsigned short int a; };
Of course, you would want each field to be 4-bytes if possible so the Pentium doesn't scream in tongues due to the wreaking havoc in memory addressing. But the unsigned short int data type clearly suggests that the struct is not aligned 32-bytes by default by the compiler.