Paul on Wed, 19 Feb 2003 16:30:33 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] gcc, assembly, etc...


I'll toss out a guess just to look stupid.  Unicode?

mike.h wrote:

void function(int i){
 char car[2];
 return;
}

If I compile and disassemble this function I'll get a line like:
0x--addr-- <function+3>: sub    $0x4,%esp

If I add another 2 char array, the line is unchanged, the compiler packs
them both into 4 bytes, same as for 2 shorts. When I add a third it
jumps to $0x8, and stays there for the 4th. If I then add a fifth, it
jumps to 0xc...12 bytes, ...Similarly, if i add the line:
int i; just before the array declaration, I'll get 0x8 subtracted.

Now, I interpret this to mean that memory is aligned on 4 byte
boundaries. However, if I change the array to char car[5]; then 0x18 (24
bytes) is subtracted from %esp and all subsequent variables will
subtract an additional 0x10 (16 bytes, unless they're too big to fit of
course). ie. Three 5-char local arrays will need 56 bytes on the stack
(0x38).

Can someone explain this behavior? I'm using gcc v 3.2. TIA




_________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce General Discussion -- http://lists.netisland.net/mailman/listinfo/plug