为什么C / C ++程序崩溃 [英] Why does C/C++ programs crash

查看:113
本文介绍了为什么C / C ++程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




为什么C / C ++程序会崩溃?


当有空指针或某些东西可以访问时程序

崩溃,但为什么会崩溃?


谢谢。

Hi,

Why does a C/C++ programs crash?

When there is access to a null pointer or some thing like that programs
crash, but why do they crash?

Thanks.

推荐答案

NewToCPP写道:
NewToCPP wrote:




为什么C / C ++程序会崩溃?


当有权访问空指针或类似程序的某些东西

崩溃时,为什么它们会崩溃?
Hi,

Why does a C/C++ programs crash?

When there is access to a null pointer or some thing like that programs
crash, but why do they crash?



你会建议什么作为替代方案?


通常情况下,这不是程序崩溃,而是操作

环境当程序试图访问不属于它的
时终止程序。例如地址0的内容。


-

Ian Collins。

What would you suggest as an alternative?

Normally it isn''t the program that crashes, but the operating
environment that terminates the program when it attempts to access
something that doesn''t belong to it. The contents of address 0 for example.

--
Ian Collins.


NewToCPP写道:
NewToCPP wrote:

为什么C / C ++程序会崩溃?
Why does a C/C++ programs crash?



首先,有些人发布了C / C ++一词。当他们显然不知道C和C ++之间的区别时,我们经常纠正它们。


在这种情况下,你要问的是为什么C系列语言的成员

崩溃了?这包括各种Small-C,K& R C,Objective-C,ISO C,ARM

C ++,ISO C ++,GNU C,GNU C ++等。每一个都有点不同!

它们都崩溃了。


(Java和C#不在列表中。它们因各种原因而崩溃。{}

for block delimiters不是C语言制作的!)

Firstly, some people post the term "C/C++" when they clearly don''t know
the difference between C and C++, so we often correct them.

In this case, you are asking "Why do members of the C family of languages
crash?" That includes various Small-Cs, K&R C, Objective-C, ISO C, ARM
C++, ISO C++, GNU C, GNU C++, and so on. Each just a little different!
They all crash.

(Java and C# are not on the list. They crash for different reasons. {}
for block delimiters does not a C language make!)


当有空指针或类似程序的东西时可以访问

崩溃,但为什么会崩溃?
When there is access to a null pointer or some thing like that programs
crash, but why do they crash?



因为C语言是为了与Assembler竞争而发明的,每当你为CPU编写不可能的指令时,
都会崩溃。例如

指向受保护的内存,或将此不可能的数字视为操作码。


此类崩溃会调用硬件保护(或更少) ,所以一个C语言将只需要依赖于那个硬件。


汇编程序无法读取所有机器语言操作码并预测

哪些会造成麻烦。同样,C语言无法预测

哪个操作序列会崩溃。根据定义,C语言可以快速编译,以创建强力汇编代码,只需很少的b $ b解释。如果没有C构造和程序集之间的简单映射

代码,那些需要速度的人就无法使用C语言。


-

Phlip

Because the C languages were invented to compete with Assembler, which
crashes whenever you write impossible instructions for the CPU. Like
"point to protected memory", or "treat this impossible number as an opcode".

Such crashes invoke hardware protection (or less), so a C language will
simply rely on that hardware.

An assembler cannot read all your machine language opcodes and predict
which ones will cause trouble. Similarly, a C language cannot predict
which sequence of operations will crash. And a C language, by definition,
compiles rapidly to create brute-force assembly code, with very little
interpretation. Without a simple mapping between C constructs and assembly
code, those who need speed could not use a C language.

--
Phlip


NewToCPP写道:
NewToCPP wrote:




为什么C / C ++程序会崩溃?


当有空指针或类似程序的某些东西时会发生这种情况

崩溃,但为什么会这样崩溃了?


谢谢。
Hi,

Why does a C/C++ programs crash?

When there is access to a null pointer or some thing like that programs
crash, but why do they crash?

Thanks.



当程序执行这样的无效操作时,
$ b是不安全的$ b继续。让它运行会造成进一步的损害。就像

车轮掉下来一样:不要继续。


-

Scott McPhillips [VC ++ MVP]

When the program performs such an invalid operation it is unsafe to
proceed. Letting it run would cause further damage. It''s just like
having a wheel fall off a car: Do not proceed.

--
Scott McPhillips [VC++ MVP]


这篇关于为什么C / C ++程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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