Structure pack()

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Structure pack()

523 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by SolomonViveros on Wed Jul 14 10:55:29 MST 2010
I'm use to Keil's #pragma pack(push,1)/#pragma pack(pop) directives...how/where is the structure packing defined in the LPCXpresso IDE?
0 项奖励
2 回复数

477 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Wed Jul 14 12:56:46 MST 2010
Not tried this in LPCXPresso, but the GCC docs suggest that #pragma pack is supported by the compiler....

http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Structure_002dPacking-Pragmas.html#Structure_002dPacking...
0 项奖励

477 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jul 14 12:32:12 MST 2010
You can pack individual structures with
[COLOR=red]__attribute__((__packed__))[/COLOR]

I suggest that the best way to use this is something like this:

#define PACKED [COLOR=red]__attribute__((__packed__))[/COLOR]

and you would define a structure like this:
struct test
{
        unsigned char  field1;
        unsigned short field2;
        unsigned long  field3;
} PACKED ;
0 项奖励