[C++]__declspec關(guān)鍵字
__declspec關(guān)鍵字
// keyword__declspec.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。 // // 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; }
posted on 2010-07-22 20:46 volnet 閱讀(1249) 評(píng)論(1) 編輯 收藏 引用 所屬分類: C/C++