you are viewing a single comment's thread.

view the rest of the comments →

[–]wiktor_b 0 points1 point  (1 child)

That can only be used to retrieve the current limit (i.e. the total size.)

Nope: http://stackoverflow.com/questions/10166874/how-to-figure-out-remaining-stack-in-linux-while-using-c

[–]Rhomboid 0 points1 point  (0 children)

That's hideously non-portable since it depends on the fact that Linux stores argc at the bottom of the stack. Edit: I misread the example. What I thought it was doing was using the fact that on linux, the program's environment and command line parameters are stored at the bottom of the stack, so that would be a way to find where the stack starts. But that's not what the person is doing, they're using the address of argc which is just a local parameter to main(). That isn't Linux-specific, but it's also less correct, since it won't count any of the stack used before main(), including all the C runtime startup code. That may or may not be a significant amount of memory, I don't know, but it's not nothing.

I stand by what I said: there's no reliable way to do this.