为什么无限递归导致赛格故障 [英] Why infinite recursion leads to seg fault

查看:113
本文介绍了为什么无限递归导致赛格故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么无穷递归导致赛格故障?
为什么堆栈溢出导致赛格故障。
我找了详细的解释。

  INT F()
{
  F();
}诠释的main()
{
  F();
}


解决方案

每次调用F(),则增加堆栈的大小,时间 - 这就是返回地址存储,因此程序知道去哪里当f ()完成。正如你永远不会退出F(),堆栈会至少有一个返回地址每次调用增加。如果堆栈段已满时,您会获得一个段错误的错误。你会得到类似的结果在每一个操作系统。

Why infinite recursion leads to seg fault ? Why stack overflow leads to seg fault. I am looking for detailed explanation.

int f()                                                                                                                                                      
{                                                                                                                                                            
  f();                                                                                                                                                       
}                                                                                                                                                            

int main()                                                                                                                                                   
{                                                                                                                                                            
  f();                                                                                                                                                       
}                                                                                                    

解决方案

Every time you call f(), you increase the size of the stack - that's where the return address is stored so the program knows where to go to when f() completes. As you never exit f(), the stack is going to increase by at least one return address each call. Once the stack segment is full up, you get a segfault error. You'll get similar results in every OS.

这篇关于为什么无限递归导致赛格故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆