What is the maximum stack level for a C ++ program?

I tried to figure out how far I can get to C ++ recursion. I wrote this function

long recurse( long level ) {
    std::cout << level << std::endl;
    return recurse( ++level ) * 12 //to avoid tail recursion optimization, if present
}

And I called it passing 0 as the first value. The last number he printed was 349411, then he printed Segmentation faultand stopped. I suppose she ran out of memory, but the same function called with the same value prints 499982 before throwing an error stack overflowin Lua, and I would be surprised if Lua functions had less weight in memory than C ++ functions.

So what is the maximum stack level a C ++ program can get before stopping it?

Is it really “as long as it has no memory”, or is there a fixed limit?

Also why is it typing Segmentation fault?

Isn't this message printed only when accessing memory in an extraneous way?

+4
source share
3 answers

The amount of memory available for recursion depends on the settings of the compiler, operating system and physical platform. There is no minimum or maximum limit.

When you run out of memory, various errors may be printed, one general message is “Segmentation Error”.

Also why does it print a segmentation error?

Is this not a message that is printed only when accessing memory in an extraneous way?

, , (), . . .

+5

, Lua , ++.

, Lua ++ Lua.

. Lua , . , Lua ( , ) ..

++ .

?

. , . , . , .

+2

, , . , , , , . , , , , Segmentation Fault, , . Stack Overflow.

0

Source: https://habr.com/ru/post/1653529/


All Articles