This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Extra space allocated for array
- From: Bob Plantz <plantz at cds1 dot net>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 20 Apr 2008 10:56:49 -0700
- Subject: Extra space allocated for array
When I simply allocate a two hundred byte array:
int main(void)
{
int myArray[50];
myArray[0] = 123;
myArray[6] = 456;
myArray[49] = 789;
return 0;
}
gcc allocates sixteen extra bytes:
main:
pushq %rbp
movq %rsp, %rbp
subq $88, %rsp
movl $123, -208(%rbp)
movl $456, -184(%rbp)
movl $789, -12(%rbp)
movl $0, %eax
leave
ret
Notice that it leaves 8 bytes "above" where the caller's rbp is stored
and the final 8 bytes of the red zone are unused. There seems to be an
8-byte buffer at both ends of the array. Why?
-- Bob