Hello
You can use __attribute__ packed for that in the compiler.
For instance
typedef struct __attribute__((packed, aligned(2))) m {
unsigned short m0;
unsigned int m1;
} m_struct ;
m_struct m_var;
This will remove padding between the field in the structure and will ensure each field is aligned to a 2 bytes boundary.
With this notation if you change your structure to typedef struct __attribute__((packed, aligned(2))) m {
unsigned char m0;
unsigned int m1;
} m_struct ;
There will be 1 byte padding between m0 and m1 and the structure size will be 6 bytes.
If you do not want any padding between the fields, you can use __attribute__ ((packed)) alone.
With the notation
typedef struct __attribute__((packed)) m {
unsigned char m0;
unsigned int m1;
} m_struct ;
There will be no padding between m0 and m1 and the size of the structure will be 5 bytes.
I hope this helps
CrasyCat