一片冰心在玉壶

那时我们有梦,关于文学,关于爱情,关于穿越世界的旅行, 如今我们深夜饮酒,杯子碰到一起,都是梦破碎的声音. 交往都是初逢,爱情都在心里,往事都在梦中, 希望都带着注释,信仰都带着呻吟. 总有善意的光逃避现世的繁琐而寻找片刻的安宁, 也许,就是你凝视这里的眼睛

博客园 首页 联系 订阅 管理
#include "stdafx.h"
#include <stdio.h>
#define PACKVALUE 4
#pragma pack(push)
#pragma pack(PACKVALUE)        
typedef struct
{
        char sa;
        double sb;
        int sc;
} innerS;
 
typedef struct
{
        int a;
        char b;
        short c;
        innerS d[2];
} testS;
 
#pragma pack(pop)
 
typedef unsigned long dword;
 
#define FSIZE(type, field) sizeof(((type*)0)->field)
#define FPOS(type, field) ((dword) & ((type*)0)->field)
//有人可能对宏定义里面的那个0不理解,你把它理解成NULL就对了 


int main(int argc, char* argv[])
{
printf("#pragma pack(%d):\nsizeof(char)=%d; sizeof(short)=%d; sizeof(int)=%d; sizeof(double)=%d\n\n",
                        PACKVALUE, sizeof(char), sizeof(short), sizeof(int), sizeof(double));
 
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, a), FPOS(testS, a));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, b), FPOS(testS, b));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, c), FPOS(testS, c));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d), FPOS(testS, d));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[0]), FPOS(testS, d[0]));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[0].sa), FPOS(testS, d[0].sa));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[0].sb), FPOS(testS, d[0].sb));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[0].sc), FPOS(testS, d[0].sc));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[1]), FPOS(testS, d[1]));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[1].sa), FPOS(testS, d[1].sa));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[1].sb), FPOS(testS, d[1].sb));
        printf("FSIZE = %d, FPOS = %d\n", FSIZE(testS, d[1].sc), FPOS(testS, d[1].sc));
        return 0;

}

 

posted on 2013-03-26 11:45  Sankye  阅读(385)  评论(0编辑  收藏  举报