Maximum Stack Size for C/C+ Program?

后端 未结 4 1892
轻奢々
轻奢々 2020-12-01 12:42

I\'ve tried the below program. The intent by which this program was created is to discover more about stack sizes.

int main()
{
    int nStack[100000000];
           


        
4条回答
  •  粉色の甜心
    2020-12-01 12:52

    What is the maximum size of the stack?

    Depends on implementation. One to few megabytes is typical on PC nowadays.

    Is it fixed for every program/computer?

    It's typically fixed on linking but standard does not define that it is. Some operating systems can limit the stack during runtime too (RLIMIT_STACK on linux for example).

    Can it be increased?

    It may be possible depending on implementation. See the documentation of your linker for details. And possibly the documentation for the OS and the executable format too.

    You should allocate huge arrays like that dynamically.

提交回复
热议问题