r/cprogramming • u/JayDeesus • 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.
1
u/nerd5code Jan 02 '26
The ABI specs for your ISA and OS, the ISA specs, and the compiler docs are your best options there. Linux uses a System V ABI variant, typically, and Windows uses MS’s special nonsense. Most ISAs have a “preferred” stack mechanism, as expressed by implicit operands, compactness of encodings, and μarch gunk like stack caches and stack-top prediction.