This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

I need some help...


Hi!

My name is Luciano, Im a student of Computer Science here in Brazil.

Im studying how memory is allocated, how the stack works for a paper, and Im 
using gcc of course! 
But Im 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. Im 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 wouldnt be 8 bytes? 
Am I right or wrong??
Why does it happen?? 
Is this some feature of gcc??


Please, Im very worried about it... youre 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]