Structure pack()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Structure pack()

509 Views
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 Kudos
2 Replies

463 Views
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 Kudos

463 Views
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 Kudos