Consider the following piece of code
#include <iostream>
typedef struct A
{
uint32_t var1;
uint32_t var2;
uint32_t var3;
uint32_t var4;
uint32_t var5;
} A_t;
typedef struct B
{
uint32_t var1;
uint32_t var2;
uint32_t var3;
uint64_t var5;
} B_t;
int main(){
std::cout << "Size of A: " << sizeof(A_t) << std::endl;
std::cout << "Size of B: " << sizeof(B_t) << std::endl;
}
Compiling this normally with gcc gives the following output
Size of A: 20
Size of B: 24
Compiling this with the -m32
flag gives this output:
Size of A: 20
Size of B: 20
Is there a difference in the way padding is done when compiling in 32bit vs 64 bits? I am on x86_64-apple-darwin17.3.0
running gcc