I have a problem in C in Keil which is below this is sample C code.
struct A
{
uint8_t header;
uint16_t volume;
uint16_t temp;
uint8_t footer;
};
union {
struct A Packet;
uint8_t buff[6];
} A_union;
The problem is I want to fill struct with a header,footer and data and serialize it with buff but union changes byte offset (I cant even see footer in buff)as you can see in the picture. how can I solve it?
Update: as Sander suggested in this link I solved the problem by modifying struct as below
struct __attribute__((__packed__)) A{
...}