Doubt about data type alignment, I'm learning about alignment now, and I have some questions, so I know double aligns to 4 bytes in linux when compiled with gcc for i386 architecture and so the address of a double has which is aligned to a multiple of 4, but it doesn't happen when I'm using the stack, only when I use data structure
#include <stdio.h>
int main(void) {
double x = 5; // 8
char s = 'a'; // +1
double y = 2; // ---- = 9 + 8 = 17 + alignment = 20
//int x = 5; // 4
//char s = 'a'; +1
//int y = 2; --------= 5 + 4 = 9 + alignment = 12
size_t a, b;
a = (size_t)&s;
b = (size_t)&y;
printf("%zu", a - b); // it wasn't supposed to be 11 instead of 15
return 0;
}
Compile: $ gcc -m32 -o align align.c
alignof(double) == 8
. – Kulseth