6
Can anyone explain to me how processing/compiling does padding? I don’t understand why the structure structc_t has a size of 24, shouldn’t it be 16 equal to structd_t? Note: Data on 64-bit Intel processor, 64-bit Windows
#include <stdio.h>
// Dados em processador Intel 64 bits, Windows de 64 bits
typedef struct structa_tag{
   char        c; // size 1
   short int   s; // size 2
} structa_t; // size 3 + 1 Padding = 4 bytes
typedef struct structb_tag{
   short int   s; // size 2
   char        c; // size 1
   int         i; // size 4
} structb_t; // size 7 + 1 Padding = 8 bytes
typedef struct structc_tag{
   char        c; // size 1
   double      d; // size 8
   int         s; // size 4
} structc_t; // size 13 + 11 Padding = 24 bytes
typedef struct structd_tag{
   double      d; // size 8
   int         s; // size 4
   char        c; // size 1
} structd_t; // size 13 + 3 Padding = 16 bytes
void main(){
   structa_t A; structb_t B; structc_t C; structd_t D;
   printf("sizeof(structa_t) = %d\n", sizeof(A));
   printf("sizeof(structb_t) = %d\n", sizeof(B));
   printf("sizeof(structc_t) = %d\n", sizeof(C));
   printf("sizeof(structd_t) = %d\n", sizeof(D));
}