Learn C the Hard Way 目录

2018-06-14  本文已影响0人  爱跑步的coder

Undefined Behaviorists

solid(2 + 2 secure) = 4

Undefined Behavior(1 + 10 UB) = 11
 At the end of string occur UB.
 Since many strings come from outside the program, it’s common for a C program to receive a string without this NULL byte.
 When it does, the C program attempts to read past the end of this string and into the memory of the computer, causing your program to crash.

avoid(3 + 4 prevent) = 7

However, you should keep in mind that avoiding the nearly random nature of UB is almost impossible, and you’ll just have to do your best.

C Is a Pretty and Ugly Language

elegant(3) = 3
solid(3) = 3
power(4) = 4
defensive programming

I approach C, and any programming, with the idea of preventing errors as best I can and assuming that nothing will work right.

All code is flawed, but the difference is that I try to assume my code is always flawed and then prevent the flaws.

上一篇 下一篇

猜你喜欢

热点阅读