Can anyone explain how the render / compile does the padding? I do not understand why the structc_t structure has a size of 24, should not it be equal to the structd_t structure? Note: Data on Intel 64-bit, 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));
}