bmp.c:8: warning: malformed '#pragma pack(push[, id], <n>)' - ignored bmp.c:33: warning: #pragma pack (pop) encountered without matching #pragma pack ...
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設置 */