This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
I need some help...
- From: Luciano Bernardes de Paula <luciano at acme-ids dot org>
- To: gcc at gnu dot org
- Date: Mon, 12 Aug 2002 17:38:58 -0300
- Subject: I need some help...
Hi!
My name is Luciano, I´m a student of Computer Science here in Brazil.
I´m studying how memory is allocated, how the stack works for a paper, and I´m
using gcc of course!
But I´m having some doubts...
I wrote a simple code like this one:
test.c
void f(int a)
{
char str[5];
}
void main (void)
{
f(1);
}
I wrote that because I wanted to know how the arguments of a function is pushed
into the stack, and how the local variables of the function are allocated.
I read that the allocation is done with quantity of memory that is multiple of
the word size. I´m testing this in a Intel machine that is 32 bits, 4 bytes.
So, I compiled this code with the command: "gcc -o test.s -S test.c" trying to
get the Assembly code of it.
In the file generated, I have read the following
f:
pushl %ebp
movl %esp, %ebp
subl $24, %esp --> here, it is allocating 24 bytes for the str variable, that
is composed by 5 positions...
I thought that 8 bytes would be allocated, because the size of the word...
Changing the size of str to 1 through 4, the size allocated is 4!
To allocate 5 positions, the amount of memory wouldn´t be 8 bytes?
Am I right or wrong??
Why does it happen??
Is this some feature of gcc??
Please, I´m very worried about it... you´re my last hope! :)
My best regards!
Luciano
--
<><><><><><><><><><><><><><><><><><><><><><><><><><><>
Luciano Bernardes de Paula - "Ruivo"
Grupo ACME!
Ibilce - UNESP - Rio Preto - SP - Brasil
<><><><><><><><><><><><><><><><><><><><><><><><><><><>
-------------------------------------------------
ACME! Computer Security Research
http://www.acme-ids.org