c - Troubles while reading the struct size -


if debug following code see size value 12 (as expected).

#include <cstdint>  int main(int argc, char *argv[]) {     typedef struct __attribute__((__packed__))  { int8_t value; } time;      typedef struct __attribute__((__packed__))  {         uint8_t msg[8]; //        time t1;         uint32_t count;     } thestruct;      thestruct s;     int size = sizeof(s);      return 0; } 

interestingly, removing comment @ "time t1;", value of size goes 16. expecting 13.

i know (more or less) explained data structure padding story...

but, there way avoid issue? in order read size = 13?

there issues mingw's emulation of msvc struct packing.

the workaround pass -mno-ms-bitfields flag compiler; cause use own layout algorithm rather attempt emulate msvc.

see struct packing , alignment mingw (arm may same issue).


Comments