I was just wondering why the stack seems to grow downwards on x86 C++
code.
A stack is a stack, doesn't matter if its x86, 8088, Z80, Forth, C, C+
+, or any other platform/language.
Its a historical relic which has sound logic to it (don't fix
something that's not broken). Way back when you use to have 2 stacks,
one that stored the program's operations and one that stored its data.
The former grew upwards, the latter downwards. If either stack got big
enough to step on the other's shoes, at least you weren't wrapping
around the memory area (register SP stack pointer overflow). The last
thing you wanted then was overwriting critical areas of your program
or loosing the top of a stack (which often meant an overwite of
critical stack pointers, ouch), sometimes causing great hardship to
more than just the program (wow, the stack pointer is now pointing
where?).
You can also look at it from another point of view, where would you
place an upward growing stack in order to provide it with enough space
to safely grow without colliding with some other allocation or part?
Placing the stack at the top and growing it down is the natural
solution. Basicly: it protects the stack's internal pointers from
being overwritten by something growing upwards like a buffer overflow.