什么导致 SIGSEGV

编程入门 行业动态 更新时间:2024-10-11 13:29:37
本文介绍了什么导致 SIGSEGV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要知道分段错误(SIGSEGV)的根本原因,以及如何处理它.

I need to know the root cause of the segmentation fault (SIGSEGV), and how to handle it.

推荐答案

维基百科有答案,以及许多其他来源.

Wikipedia has the answer, along with a number of other sources.

段错误基本上意味着您对指针做了坏事.这可能是一个段错误:

A segfault basically means you did something bad with pointers. This is probably a segfault:

char *c = NULL; ... *c; // dereferencing a NULL pointer

或者这个:

char *c = "Hello"; ... c[10] = 'z'; // out of bounds, or in this case, writing into read-only memory

或者这样:

char *c = new char[10]; ... delete [] c; ... c[2] = 'z'; // accessing freed memory

每种情况下的基本原则相同 - 你正在用不属于你的记忆做某事.

Same basic principle in each case - you're doing something with memory that isn't yours.

更多推荐

什么导致 SIGSEGV

本文发布于:2023-07-14 10:37:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SIGSEGV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!