Quoting the second paragraph of BUGS
section, from manpage of alloca(3)
On many systems
alloca()
cannot be used inside the list of arguments of a function call, because the stack space reserved byalloca()
would appear on the stack in the middle of the space for the function arguments.
I failed to see how this would happen. Taking the following code as example:
void f(int a, void * b, int c);
int
main(void)
{
f(1, alloca(100), 2);
}
Based on my understanding, alloca
expands the stack frame for main
down 100 bytes (by modifying stack pointer register), then the pointer to that block of stack memory (along with 2 int
s) is passed on stack frame for f
. So the allocated space shouldn't be in the middle of a
, b
or c
, actually it should be on a different frame (which is on frame for main
in this case).
So what's the misunderstanding here?