To achieve this, you can add an attribute ((packed)) into individual data items. In this case, packaging is applied to the data item, so there is no need to restore the old mode.
Example: For structures:
typedef struct _MY_STRUCT { }__attribute__((packed)) MY_STRUCT;
For data members:
struct MyStruct { char c; int myInt1 __attribute__ ((packed)); char b; int myInt2 __attribute__ ((packed)); };
Neon glow
source share