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 .