c6657怎么struct对齐

2019-03-26 15:51发布

我用了#pragma STRUCT_ALIGN(BITMAPFILEHEADER,1);
但是貌似不行

struct如下:
typedef struct  {
        WORD    bfType;
        DWORD   bfSize;
        WORD    bfReserved1;
        WORD    bfReserved2;
        DWORD   bfOffBits;
} BITMAPFILEHEADER;
#pragma STRUCT_ALIGN(BITMAPFILEHEADER,1);


winhex下看到的要读取的文件的存储结构如下:
42 4D 36 B8 0B 00 00 00 00 00 36....

但是单步调试时查看到的是这样:
bfType:424D
bfSize:0B000000
bfReserved1:0000
...
其中 36 B8 被跳过了。

新手求助,望高手解答

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
kooking
2019-03-27 00:16
< #pragma pack(2)有这个试试

#pragma pack(n)
      This pragma will affect following declaration until next pack(n) exists, forcing the maximum alignment of each field to be the value represented by n. Valid values for n are 1, 2, 4, 8, and 16 bytes.

一周热门 更多>