c++ - 为什么写c语言很容易core down?
伊谢尔伦
伊谢尔伦 2017-04-17 13:04:59
0
9
1027
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(9)
刘奇

Two aspects. From a language perspective, C language does not have its own memory management mechanism, while languages ​​​​such as Java, C#, and js have their own memory management mechanisms. Memory management is an area where problems are prone to occur, and it places high demands on programmers.
From a runtime perspective, most C languages ​​are compiled and run directly on the hardware, and any errors are directly reflected on the hardware; in contrast, interpreted languages ​​or languages ​​that are compiled and run on a virtual machine, the interpreter Or the virtual machine itself will do a lot of checks during execution to avoid crashes as much as possible.

巴扎黑

It should be that there is a loophole in the program design, which reflects the loopholes in the code design in operation.
C language requires a comprehensive understanding of compiler features and related underlying computer knowledge

On the other hand, look at the code of experts and debug more. Get familiar with the compiler and use mature monitoring tools

大家讲道理

Correct a spelling error core dump

阿神

Most languages ​​have similar problems, just with a different name
The C version is called segmentation fault (look at the name of this website)
C++ also has segmentation fault, and there are various exceptions
Java's called NullPointerException and ArrayOutOfIndex
in dynamic language become NoMethodError or No attribute or undefined is not a function, etc. In essence, it is still NullPointerException

Of course, C and C++ are more prone to this kind of problem
Because C and C++ need to manually release the memory and do it wrong (release the wrong location/use it again after releasing/release it and think it is not released, but someone else uses it) If it is released during reuse, etc.) there will be a segmentation fault
With GC in Java, etc., the memory can be used without releasing it, so these problems disappear
However, the carelessness of programmers is unlimited, so you will still encounter to NullPointerException and ArrayOutOfIndex…

小葫芦

No one wants it to go wrong when designing a program
C language has too many memory operations and is too easy to cross the line
It is difficult to write excellent code without certain experience~

大家讲道理

This kind of programming language, in partial terms, is "literally translated into assembly". In addition to having the basic form of a modern compiled language, it actually follows a relatively low-level development route. In addition, because programmers are allowed to use pointers at will, The compiler doesn't dare to care too much. Therefore, the quality requirements for developers themselves are much higher. For people like me who have only learned JS, C language basically manages everything by themselves...

刘奇

Developer level issue
Isn’t linux/unix relatively stable?

阿神

The main problem is that when using C language, the memory is managed by the programmer himself. If the memory management is not good, it will hang.
Typical:

  1. Null pointer access causes the program to hang.

  2. Wild pointer access, for example, if the content pointed to by a certain pointer is invalid, then accessing the uncontrollable pointer will cause the program to hang.

  3. Memory out-of-bounds access, which is commonly referred to as "memory being stepped on", such as an array being written out-of-bounds into the memory, modifying an unknown data area. This operation is extremely dangerous and hidden, and is often difficult to locate.
    The C language leaves many things to the programmers to manage. While improving flexibility and performance, there are also stability risks. This is a double-edged sword. Only by improving your level can you be more comfortable, otherwise it may be counterproductive.

迷茫

In fact, the real reason is human reason.

Many languages, such as C# and Java, have a well-designed exception handling system. Many programmers would rather risk data errors than crash the program, so they catch everything they do and log unfamiliar exceptions somewhere and ignore them.

However, C language does not have such a trouble-free approach. Although the same program is poorly written, it is easy to fail in C language.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!