This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]