This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
variables and stack space question
- From: "Hudak, Tyler" <Tyler dot Hudak at roadway dot com>
- To: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Date: Tue, 8 Jan 2002 13:44:14 -0500
- Subject: variables and stack space question
Hello,
I'm confused on how stack space for variables are handlted. In the
function
foo, a 5-byte string, buf2, is created. I would expect the stack to
only be subtracted 8 bytes to make room for this, but when I generate
the assembly output for it (with gcc -s), 24 bytes are subtracted on
the stack. Why so much? Does this have to do with alignment? If so,
where can I find more information on this. Thanks. If you need to
know, I'm running RH 7.1 on a P3 with gcc 2.96.
Tyler
prog.c:
void foo (int a, int b, int c)
{
char buf2[5];
}
void main()
{
foo(1,2,3);
}
prog.asm:
.file "ex1.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp, %ebp
subl $24, %esp <----------- space on stack for buf2 created
here
leave
ret
.Lfe1:
.size foo,.Lfe1-foo
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
subl $4, %esp
pushl $3
pushl $2
pushl $1
call foo
addl $16, %esp
leave
ret
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-81)"