什么是C ++中的SIGSEGV运行时错误? [英] What is SIGSEGV run time error in C++?

查看:263
本文介绍了什么是C ++中的SIGSEGV运行时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道分段错误的根本原因,也可以告诉我如何处理它。

I need to know the root cause of the segmentation fault, and also can anyone tell me how to handle it.

推荐答案

维基百科提供了答案以及其他一些来源。

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

segfault基本上意味着你使用指针做了一些坏事。这可能是一个segfault:

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.

这篇关于什么是C ++中的SIGSEGV运行时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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