MyMSDN

MyMSDN记录开发新知道

[C++]__declspec关键字

__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;
}

posted on 2010-07-22 20:46 volnet 阅读(1235) 评论(1)  编辑 收藏 引用 所属分类: C/C++

评论

# re: [C++]__declspec关键字 2010-08-29 17:28 evening dresses

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  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


特殊功能