Use the "packed" attribute against the members of a structure. This attribute
mechanism is an extension to the GNU C compiler. An example of how you would do this is
unsigned char field1 __attribute__((__packed__));
unsigned short field2 __attribute__((__packed__));
unsigned long field3 __attribute__((__packed__));
} var1, var2;
Note the use of the keyword "__attribute__" with the attribute
"__packed__" within the double brackets (before the terminating semicolon of
each member variable declaration).
An alternate way of doing the above is as below.
unsigned char field1;
unsigned short field2;
unsigned long field3;
typedef struct test test_t;
test_t var1, var2;
This will ensure that all members of the structure are packed. Note that this doesn't
seem to work right if you try to combine the typedef and the struct definition or if you
combine variable declarations with the structure definition.