Given the following code:
typedef struct tagRECT {
int left;
int top;
int right;
int bottom;
} RECT;
extern int Func(RECT *a, int b, char *c, int d, char e, long f, int g, int h, int i, int j);
int main() {
}
void gui() {
RECT x = {4, 5, 6, 7};
Func(&x, 1, 0, 3, 4, 5, 6, 7, 8, 9);
}
This is the assembly generated gcc x86_64 presumably on linux (I used compiler explorer).
main:
mov eax, 0
ret
gui:
push rbp
mov rbp, rsp
sub rsp, 16
; RECT x assignment
mov DWORD PTR [rbp-16], 4
mov DWORD PTR [rbp-12], 5
mov DWORD PTR [rbp-8], 6
mov DWORD PTR [rbp-4], 7
; parameters
lea rax, [rbp-16]
push 9
push 8
push 7
push 6
mov r9d, 5
mov r8d, 4
mov ecx, 3
mov edx, 0
mov esi, 1
mov rdi, rax
call Func
add rsp, 32
nop
leave
ret
It can be seen that the int
in the struct are aligned by 4 bytes. But the last 4 parameters to the function, all int
are push
d to the stack which means they were aligned by 8 bytes. Why this inconsistency?