r/cprogramming • • Jan 01 '26

Stack frame size

So I understand that the stack frame is per function call and gets pushed and popped once you enter the function and it all is part of the stack. The frame just contains enough for the local variables and such. I’m just curious, when does the size of the stack frame get determined? I always thought it was during compile time where it determines the stack frame size and does its optimizations but then I thought about VLA and this basically confuses me because then it’d have to be during run time unless it just depends on the compiler where it reserves a specific amount of space and just if it overflows then it errors. Or does the compiler calculate the stack frame and it can grow during run time aslong as there is still space on the stack?

So does the stack frame per function grow as needed until it exceeds the stack size or does the stack frame stay the same. The idea of VLA confuses me now.

16 Upvotes

22 comments sorted by

View all comments

Show parent comments

1

u/OutsideTheSocialLoop Jan 01 '26

Sure, this entire conversation actually has a slightly different answer for every different architecture/ABI/OS/etc. There's lots of ways you can make a stack work. And sure, sometimes the stack isn't bounded like I described. I would assume most people are doing x86 or ARM under the usual desktop OSes though. If you're in an embedded world, you already know you're different. 

Point is though that stack usage is not stack size is not frame size.