Re: Why gcc translate a c program into assemble as follow
- From: Tim Roberts <spamtrap@xxxxxxxxxx>
- Date: Thu, 27 Oct 2005 03:16:03 +0000 (UTC)
"Zheng Da" <spamtrap@xxxxxxxxxx> wrote:
>
>A C function is like below:
>void echo()
>{
> char buf[4];
> gets(buf);
>}
>I use gcc compile it with the option -O2 -S, and get the following
>assemble program:
>echo:
> pushl %ebp
> movl %esp,%ebp
> leal -4(%ebp),%eax
> subl $20,%esp ##why allocate 20 bytes on stack? The variable in C
>function is only 4 bytes
> pushl %eax
> call gets
> leave
> ret
This question comes up approximately once a week.
There have been many mumbled attempts at an explanation for this, usually
involving vague words about stack alignment. In my 15 years here, no one
has ever produced a completely satisfactory explanation of this odd
behavior on gcc's part.
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- Follow-Ups:
- Re: Why gcc translate a c program into assemble as follow
- From: wanderer83
- Re: Why gcc translate a c program into assemble as follow
- References:
- Why gcc translate a c program into assemble as follow
- From: Zheng Da
- Why gcc translate a c program into assemble as follow
- Prev by Date: Re: improve strlen
- Next by Date: Re: compiler generated output
- Previous by thread: Re: Why gcc translate a c program into assemble as follow
- Next by thread: Re: Why gcc translate a c program into assemble as follow
- Index(es):