Mail Archives: djgpp/2001/06/27/14:00:12
Kent Dahl wrote:
> > 00000000 55 push ebp
> > 00000001 89E5 mov ebp,esp
> > 00000003 83EC04 sub esp,byte +0x18
> > 00000006 C745FC78563412 mov dword [ebp-0x4],0x12345678
> > 0000000D C9 leave
> > 0000000E C3 ret
> >
> > The third line reserves 18 bytes.
>
> Does it? First of all, its 0x18 bytes, aka 24 bytes.
> Are you sure it isn't just padding for alignment?
If you read before posting, you'll see the third line allocates 4
bytes. 83 is the opcode for immediate subtract, where the EC indicates
the register ESP operand and 04 is the value 4 being s subtracted.
>
> If I add yet another int, the number doesn't increase...
>
> <CODE>
> int main ()
> {
> int i;
> i = 0x12345678;
> int j;
> j = 0xCAFEBABE;
> }
> </CODE>
>
Gee, my G++ 2.91.66 does no such thing. It allocates
exactly 4 (with the similar code as the original poster) and
8 with the above code. Of course, this is really all quite
a silly discusion, if you turn on the optimizer, it emits
main:
pushl %ebp
movl %esp,%ebp
xorl %eax, %eax
leave
ret
I.e., it doesn't allocate anything. It realizes you aren't doing
anything with either one of those variables and optimizes them
both away.
- Raw text -