J
jacob navia
Flash said:jacob navia wrote, On 10/01/08 20:27:
Of course, if you do not call main recursively the compiler might decide
to allocate foo where it allocates "global" variables. I can see reasons
why this optimisation might make sense.
You are daydreaming.
I bet you can't name a single compiler that does that kind of nonsense!
Of course, if the stack grows in the opposite direction (as it does on
the PowerPC) it could give very unexpected results.
And the fix is to take the absolute value... We are interested in the
distance.
Not to mention on
embedded compilers which people have posted about as recently as this
week that do things like allocating *all* local variables statically.
Who cares?
We are speaking about STACK OVERFLOW here, so those compilers are
OFF TOPIC for this thread.
However you have no way of knowing (in general) what limit you need to
test against, so it does not help you.
Of course you know, and if you don't you can measure it with a program
like the above one.
#include <stdio.h>
char *StartOfStack;
int main(int argc,char *argv[])
{
char foo,*p;
char m[8192*16];
if (argc > 0)
p = StartOfStack = &foo;
else
p = &foo;
printf("Stack %d\n",StartOfStack-p);
main(0,NULL);
// Not reached
}
Output:
Stack 0
Stack 131100
Stack 262200
Stack 393300
Stack 524400
Stack 655500
Stack 786600
You can adjust the size of the array to make more finer measures.
Apart from PowerPC and related processors (because you have the stack
direction wrong), so it won't work on big iron (or even relatively small
servers like those we run our accounts system on in my company) from IBM
or Apples from before they switched to x86 processors, or the afore
mentioned embedded compilers...
HELLO HELLO
This thread is about stack overflows!
We are speaking about stack overflows here.
http://dictionary.reference.com/browse/pedant
pedant
–noun
1.a person who makes an excessive or inappropriate display of learning.
2.a person who overemphasizes rules or minor details.
3.a person who adheres rigidly to book knowledge without regard to
common sense.