warning malformed '#pragma pack(push[, id], n)' - ignored

bmp.c:8: warning: malformed '#pragma pack(push[, id], <n>)' - ignored

bmp.c:33: warning: #pragma pack (pop) encountered without matching #pragma pack (push, <n>)

这个警告很重要不能忽略,我遇到的这个问题适用于编译器比较老的,因为韦东山自带的虚拟机Ubuntu9.10用的是/work/tools/gcc- 3.4.5 -glibc -2.3.6,而视频里用的编译器是4.3几,编译器比较高

,这个警告是说结构体对齐的问题。对于自带的较低的编译器解决此问题很简单: 修改BMP文件里的两个结构体

#include <config.h>

#include <pic_operation.h>

#include <picfmt_manager.h>

#include <file.h>

#include <stdlib.h>

#include <string.h>

//#pragma pack(push) /* 将当前pack设置压栈保存 */

//#pragma pack(1) /* 必须在结构体定义之前使用,这是为了让结构体中各成员按1字节对齐 */

typedef struct tagBITMAPFILEHEADER { /* bmfh */

unsigned short bfType;

unsigned long bfSize;

unsigned short bfReserved1;

unsigned short bfReserved2;

unsigned long bfOffBits;

} __attribute__((packed)) BITMAPFILEHEADER;

typedef struct tagBITMAPINFOHEADER { /* bmih */

unsigned long biSize;

unsigned long biWidth;

unsigned long biHeight;

unsigned short biPlanes;

unsigned short biBitCount;

unsigned long biCompression;

unsigned long biSizeImage;

unsigned long biXPelsPerMeter;

unsigned long biYPelsPerMeter;

unsigned long biClrUsed;

unsigned long biClrImportant;

} __attribute__((packed)) BITMAPINFOHEADER;

//#pragma pack(pop) /* 恢复先前的pack设置 */

上一篇:js获取数组中最大值,最小值


下一篇:gitlab分支代码本地拉取及jenkins关联gitlab分支