I have the code:

#define PACKED __attribute__((packed)) struct PACKED TgaHeader { uint8_t id_length; uint8_t color_map_type; uint8_t image_type; /* Color Map Specification (5 bytes) */ uint16_t first_entry_index; uint16_t color_map_length; uint8_t color_map_entry_size; /* Image Specification (10 bytes) */ uint16_t x_origin; uint16_t y_origin; uint16_t width; uint16_t height; uint8_t pixel_depth; uint8_t image_descriptor; }; typedef struct TgaHeader TgaHeader; 

If you add up the dimensions of each field of the structure separately, you should get 18, but:

 printf("%zu\n", sizeof(TgaHeader)); /* —→ 20 */ 

Compiler: gcc version 6.3.0 (MinGW.org GCC-6.3.0-1) .
I compile this way: gcc si.c -o si.exe -lgdi32 -std=c11 -Wall -Wextra -Wpedantic -pedantic .

  • It seems system-dependent. 6.3.0 on the 64-bit debian gives 18. - Alexander Prokoshev

1 answer 1

Some Google has shown that this is a confirmed bug in minGW , stretching from the 12th year and sort of eliminated in the eighth version of the compiler. The recommended traversal is to use the -mno-ms-bitfields flag when compiling -mno-ms-bitfields