Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size of a stack frame always fixed?

During a C++ program execution does stack frame of a particular function always have a constant size or compiler is allowed to do dynamic stack management in some cases, something similar to what alloca() function does? to better describe it I mean offset of a particular local variable or object in the stack frame may change at different executions of function

like image 921
Pooria Avatar asked Feb 16 '23 01:02

Pooria


1 Answers

At least in most typical implementations, the stack frame for a variadic function varies depending on how many variables are passed. For example:

printf("%d", 1); // stack frame contains 1 pointer, one int
printf("%d %d", 1, 2); // stack frame contains one pointer, 2 ints.

Whether the implementation is particularly similar to alloca depends on the implementation though (especially since alloca isn't standard, so how or even if it's implemented may vary).

like image 144
Jerry Coffin Avatar answered Feb 23 '23 00:02

Jerry Coffin