mike.h on Wed, 19 Feb 2003 11:01:07 -0500 |
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 -- -mike.h _________________ mike.h@acm.org mike.h@stemik.com __________________________________________ Democracy is the worst form of government; except for all those other forms that have been tried from time to time. -Winston Churchill __________________________________________ GnuPG public key: //http://www.stemik.com/~mike.h/mike.h.asc Attachment:
signature.asc
|
|