0

I wrote a function in file example1.c as below:

void function(int a)
{
    char buffer1[1];
}

When used "gcc -S -o example1.s example1.c, I got the following assembly code:

_function:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
leave
ret

And if I change buffer1[1] to buffer1[2] or buffer1[4], the assembly code is the same. However, when I wrote buffer1[3] instead of buffer1[1], I got the following assembly code:

_function:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
leave
ret

I don't know why. Who can tell me the reason? Thank you.
My PC:
CPU:AMD Turion 64 X2
Memory: DDR2 667
OS:Windows XP Home SP3

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Duoas
0

Looks like it is being stupid about alignment?

Yeah, I really get confused about alignment. I have read some articles about alignment but still couldn't find the answer.

0

A structure is 'aligned' in memory to make it easy to access quickly. Search your compiler's documentation for "record alignment".

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.