Memory Allocation On Stack
\ Pankaj Kohli (20 Jul 2007)
. \ kanishk rastogi (20 Jul 2007)
. . \ Pankaj Kohli (20 Jul 2007)
. . . \ kanishk rastogi (20 Jul 2007)
. . . \ Tim Prince (20 Jul 2007)
. \ Andrew Haley (20 Jul 2007)
. . \ Pankaj Kohli (20 Jul 2007)
. . . \ Tom St Denis (20 Jul 2007)
. . . \ Andrew Haley (20 Jul 2007)
. . . . \ Pankaj Kohli (21 Jul 2007)
. . . . . \ John (Eljay) Love-Jensen (21 Jul 2007)
. . . . . . \ Pankaj Kohli (22 Jul 2007)
. . . . . \ Andrew Haley (22 Jul 2007)
. . . . . \ Rask Ingemann Lambertsen (22 Jul 2007)

2 msgbug around inline asm, or expected?
1 msgInstalling gcc-3.2
1 msgfield 'fucntion_name 'declared as a function
2 msgdebugging inline assembler
1 msgISO C++ forbids declaration of `result_type' wi...
1 msgunrecognizable insn error
2 msgObject of abstract type
4 msgCrosstools and dynamic libraries
1 msgdll's?
1 msgSind Sie doof?
2 msgException handling when mixing C++ et C shared ...
2 msgGCC design document and architechture
3 msgCore dump using __cxa_demangle
2 msggcc optimization flag breakdown
4 msgFW: GCC assembler errors on all Intellistore ma...
1 msgregarding basic blocks
4 msgError referencing symbols in gdb when compiled ...
3 msgRe: gcc-help Digest 17 Jul 2007 16:12:44 -0000 ...
1 msggcc 4.0 on Mac OS X 10.3
Subject:Memory Allocation On Stack
Group:Gcc-help
From:Pankaj Kohli
Date:20 Jul 2007


Hi,

I wrote a simple C program to test the memory allocation for local
variables. But when i try to disassemble the program using gdb, it
shows that 16 bytes are being reserved for local variables on the
stack, although i declared a single integer variable which is supposed
to take only 4 bytes.
Can anyone tell, why it is reserving 16 bytes on the stack for just a
single variable ? Is it some kind of optimization done by gcc ?
Does the exact value depends on the operating system and/or gcc version ?

#include <stdio.h>
int main(int argc, char **argv) {
int x=10;

return 0;
}

Breakpoint 1, main () at test7.c:4
4 int x=10;
(gdb) disassemble main
Dump of assembler code for function main:
0x08048344 <main+0>: lea 0x4(%esp),%ecx
0x08048348 <main+4>: and $0xfffffff0,%esp
0x0804834b <main+7>: pushl 0xfffffffc(%ecx)
0x0804834e <main+10>: push %ebp
0x0804834f <main+11>: mov %esp,%ebp
0x08048351 <main+13>: push %ecx
0x08048352 <main+14>: sub $0x10,%esp
0x08048355 <main+17>: movl $0xa,0xfffffff8(%ebp)
0x0804835c <main+24>: mov $0x0,%eax
0x08048361 <main+29>: add $0x10,%esp
0x08048364 <main+32>: pop %ecx
0x08048365 <main+33>: pop %ebp
0x08048366 <main+34>: lea 0xfffffffc(%ecx),%esp
0x08048369 <main+37>: ret
End of assembler dump.

--
- Pankaj


© 2004-2008 readlist.com