分段错误和堆栈溢出有什么区别? [英] What is the difference between a segmentation fault and a stack overflow?

查看:24
本文介绍了分段错误和堆栈溢出有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我们调用递归函数时,连续的调用存储在堆栈中.但是,由于错误,如果它无限持续下去,则错误是分段错误"(如 GCC 所示).

For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is 'Segmentation fault' (as seen on GCC).

不应该是堆栈溢出"吗?那么两者的基本区别是什么呢?

Shouldn't it have been 'stack-overflow'? What then is the basic difference between the two?

顺便说一句,解释会比维基百科链接更有帮助(通过它,但没有对特定查询的回答).

Btw, an explanation would be more helpful than wikipedia links (gone through that, but no answer to specific query).

推荐答案

Stack overflow is [a] cause,segmentation fault is the result.

Stack overflow is [a] cause, segmentation fault is the result.

至少在 x86 和 ARM 上,堆栈"是一块保留用于放置局部变量和函数调用返回地址的内存.当堆栈耗尽时,将访问保留区域之外的内存.但是应用程序并没有向内核询问这块内存,因此会产生一个 SegFault 来保护内存.

At least on x86 and ARM, the "stack" is a piece of memory reserved for placing local variables and return addresses of function calls. When the stack is exhausted, the memory outside of the reserved area will be accessed. But the app did not ask the kernel for this memory, thus a SegFault will be generated for memory protection.

这篇关于分段错误和堆栈溢出有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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