递归的main() - 为什么它会出现段错误? [英] Recursive main() - why does it segfault?
本文介绍了递归的main() - 为什么它会出现段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么下面的程序段错误?
Why does the following program segfault?
int main() { main(); }
即使它是不结束,因此定义无效的递归,我不明白为什么它出现segfaults(GCC 4.4.3和1.5铿锵(干线))。
Even though it is a recursion that does not end and is therefore invalid by definition, I don't see why it segfaults (gcc 4.4.3 and clang 1.5 (trunk)).
推荐答案
由于每次调用自身一次分配的堆栈空间一点点;最终它运行的堆栈空间和段错误。我有点惊讶它去了段错误,虽然,我本来期望(鼓声)堆栈溢出!
Because every time it calls itself it allocates a little bit of stack space; eventually it runs out of stack space and segfaults. I'm a bit surprised it goes with a segfault, though; I would have expected (drum roll) stack overflow!
这篇关于递归的main() - 为什么它会出现段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文