我有一个用于嵌入式ARM处理器的递归下降解析器(在C + GCC中,用于ARM Cortex M3).
在运行它的同时我注意到它使用了大量的堆栈空间(甚至超出了你的预期)并且经过仔细检查我发现这种情况正在发生:
extern int bar(int *p);
int foo() {
int z = foo(); // it's an example!
int n[100]; // stack usage
return z+bar(n); // calling bar(n) stops n from being optimised out
}
Run Code Online (Sandbox Code Playgroud)
运行arm-none-eabi-gcc -fomit-frame-pointer -S test.c的结果
foo:
str lr, [sp, #-4]! ; Push link register
sub sp, sp, #412 ; Reserve space on stack, even if we don't need it now!
bl foo ; Recurse
str r0, [sp, #404] ; Store result
... …Run Code Online (Sandbox Code Playgroud)