4 ms·
Too many people still don't understand C's greatest failure: the undefined behavior. Most people assume that if you write past an array then the result may be a
by H8crilA 2y ago
Too many people still don't understand C's greatest failure: the undefined behavior. Most people assume that if you write past an array then the result may be a program crash; but actually undefined behavior includes other wonderful options such as stealing all your money, encrypting all your files and extorting you for some bitcoin, or even partially destroying a nuclear isotopes processing facility. Undefined really means undefined, theoretically some demons may start flying out of your nose and it would be completely up to spec. If you think that this is justified by "performance gains" or some other nonsense then I really don't know what to tell you!
- inopinatus 2y agoNo, it doesn't. It means the C standard imposes no requirements. It does not mean the compiler becomes unconstrained by statutory law or physics, and if your compiler is actually malware then it is not politely waiting for undefined behaviour before injecting a payload. The notorious nasal demons may not be in conflict with the C standard, but they are not going to actually happen, because they only exist in the imagination. The example is given to illustrate by absurdity that the scope of consequential defects is greater than "your program may crash", that's all. If you do wish to produce a similar effect then I suggest consuming a bowl of Buldak instant noodles whilst inducing a sneeze during compilation. Warning: your sinuses will not thank you. And cover your keyboard. The biggest hazard with undefined behaviour is that the compiler is not required to issue warnings or errors when encountered.
- rramadass 2y agoThanks for straightening out people's absurd ideas about UB. It is instructive to read what Ritchie himself thought of various UBs "specified" by the ANSI committee - https://news.ycombinator.com/item?id=20171616 https://news.ycombinator.com/item?id=20171616
- saagarjha 2y agoTypically this view is proposed because a malicious attacker can actually make your program do all sorts of stuff you probably did not expect, including adding "functionality" that you did not include in your program.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- astrange 2y agoYou don't have to implement the compiler that way if you don't want to. UBSan is fast enough to ship with it on and there's -fbounds-safety.