Saturday, 8 July 2017

Structure alignement

typedef struct data {
    uint16_t  d1;
    uint8_t  d2;
    uint16_t d3;
    uint32_t d4;
}Data;

 Sizeof(Data)==>12bytes


 Packeted the structure
typdef struct data {
    uint16_t  d1;
    uint8_t  d2;
    uint16_t d3;
    uint32_t d4;
} __attribute__((packed))Data;

Sizeof(Data)===> 9bytes.

No comments:

Post a Comment