本文介绍了是什么导致了 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 04:50