3 ms·
I often see people still choose C even in 2020 for some projects. The usual arguments are that C has stuck with us for several decades and that it is now rock s
by imtringued 7y ago
I often see people still choose C even in 2020 for some projects. The usual arguments are that C has stuck with us for several decades and that it is now rock solid. Articles like this make me think otherwise. Why do modern compilers break old code and then claim that it was broken from the start?
- saagarjha 7y agoBecause the code was broken from the start, and previous compilers just didn't have the machinery to recognize that or do anything useful with it.
- aw1621107 7y ago> Why do modern compilers break old code and then claim that it was broken from the start? Because strictly speaking that old code is broken in that it violates the standard. Older compilers either didn't use the more aggressive interpretation of undefined behavior or didn't implement the optimizations that resulted in bad runtime behavior.
- jcranmer 7y agoThe code was broken from the start. Most of the undefined behavior in C arises from traps: if your code, naively translated, would have resulted in a trap, then it is undefined behavior in C. Preserving when--and even if--a trap occurs is generally not desired, even by most end users. The instructions most likely to cause traps (memory operations and division operations) are expensive, and hoisting them outside of loops, or dead-code eliminating them is incredibly desirable. When people complain about "broken" undefined behavior, what they usually mean is that they expected to get a very particular kind of trap and the compiler didn't give them that trap.
- kps 7y agoContrary to your other replies — old code, written in K&R C, was not broken from the start. ANSI C broke it with undefined behavior (by accident, I think) and ‘volatile’ (not by accident, just not fully thought through).
- madmax96 7y agoCompiler sanitizers and tools like Valgrind can go a long way to help developers understand why a program is broken.