__declspec关键字
// keyword__declspec.cpp : 定义控制台应用程序的入口点。
//
// ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/kernel_d/hh/Kernel_d/64bitAMD_6db3322a-fe6d-4287-9eda-a9c1378e715d.xml.htm
// The sizeof value for any structure is the offset of the final member,
// plus that member's size, rounded up to the nearest multiple of the largest
// member alignment value or the whole structure alignment value,
// whichever is greater.
#include "stdafx.h"
__declspec( align( 32) ) struct Struct__declspec_1
{
int a;
int b;
};
__declspec( align( 32) ) struct Struct__declspec_2
{
__declspec( align( 64) ) int a;
int b;
};
__declspec( align( 8 ) ) struct Struct__declspec_3
{
int a; //4 bytes
int b; //4 bytes
int c; //4 bytes
};
__declspec( align( 8 ) ) struct Struct__declspec_4
{
int a; //4 bytes
int b; //4 bytes
};
struct StructNormal
{
int a; //4 bytes
int b; //4 bytes
int c; //4 bytes
};
int _tmain(int argc, _TCHAR* argv[])
{
printf( "sizeof Struct__declspec_1 is %d.\n", sizeof( Struct__declspec_1 )); //32
printf( "sizeof Struct__declspec_2 is %d.\n", sizeof( Struct__declspec_2 )); //64
printf( "sizeof Struct__declspec_3 is %d.\n", sizeof( Struct__declspec_3 )); //16
printf( "sizeof Struct__declspec_4 is %d.\n", sizeof( Struct__declspec_4 )); //8
printf( "sizeof StructNormal is %d.\n", sizeof( StructNormal )); //12
return 0;
}