Be care of the Byte Alignment in Type Cast.

Be care of the Byte Alignment in Type Cast.

For example, if you have one buffer(void*) with data follow this structure:

typedef  struct {
  uint8_t a;
  uint8_t b;
  uint32_t c;
} xxx_t

Normally,  it needs 6 bytes per data, right?  But, actually, when you did type cast, like (xxx_t*)buffer the data will be totally wrong (probably a and b is right, but c is holy shit).

The root cause, is Byte alignment.