Search code examples
c++visual-c++

What is the maximum number of local variables in a function that VC++ can allow?


This is just out of curiosity. I read an old joke somewhere that made reference to an inordinately huge number of variables being declared in a function and the VC++ compiler wouldn't compile.

I would assume it would depend on the size of the integer used to keep reference of the variables, no ? Or is this no longer the case and you can have as many local variables as you'd want ?


Solution

  • Without a reference it is hard to know what the original issue was but it looks like the default stack size in Visual Studio is 1 MB but you can set it using /F. This will indeed limit the number of local variables you can declare, this is usually an issue when someone wants to declare a really large array on the stack.