How to increase stack/recursion depth of g++ in Linux?
            Asked
            
        
        
            Active
            
        
            Viewed 162 times
        
    0
            
            
        - 
                    Question https://stackoverflow.com/questions/2630054/does-c-limit-recursion-depth can be useful in this case. – Mihai8 Aug 28 '21 at 22:49
- 
                    @JaMiT Thanks for pointing it out. I have posted this question with an answer but mistakenly write "the following code will work" in the question itself. – Naman Jain Aug 29 '21 at 03:44
- 
                    @Mihai8 Thanks! https://stackoverflow.com/questions/2630054/does-c-limit-recursion-depth is informative. – Naman Jain Aug 29 '21 at 03:49
- 
                    @NamanJain OK, that looks more understandable. So your question is a duplicate of [Change stack size for a C++ application in Linux during compilation with GNU compiler](https://stackoverflow.com/questions/2275550/) – JaMiT Aug 29 '21 at 03:51
1 Answers
0
            
            
        You need to include a header file
#include <sys/resource.h>
and in the main() function you need to write these lines as...
int main(){
 rlimit R; // Unsigned integral type used for limit values.
 getrlimit(RLIMIT_STACK, &R);
 R.rlim_cur = R.rlim_max; // Limit on stack size. 
 setrlimit(RLIMIT_STACK, &R);
 // your code
}
Learn more about <sys/resource.h> here.
 
    
    
        Naman Jain
        
- 195
- 2
- 15
