The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Vincent Hui (6) [Avatar] Offline
#1
We know we must avoid stack overflow. However, how can we know how much free stack size left in run-time? So that we can handle low stack size condition in run-time.

Thanks
Ivan Cukic (104) [Avatar] Offline
#2
As far as I know, there is no portable way to do this. You could test it for each platform you run your program on and hard-code it (I've seen people doing this), but I would advise against it.

Stack size is not something you should rely on. Recursion is sometimes fun, but C++ is not the language where you want to overuse it.

There will be a possibility to achieve deep recursion in C++ with the coroutines language extension planned for C++20, but still, it is a hack and not something that should be (ab)used.