4 ms·
Undefined behavior permits backwards compatibility to be broken, because when a compiler adds a new optimization that exploits UB, existing programs can change
by agwa 3y ago
Undefined behavior permits backwards compatibility to be broken, because when a compiler adds a new optimization that exploits UB, existing programs can change behavior, breaking code that previously worked. The blog post cites infinite loops as an example. Thus, eliminating UB would improve backwards compatibility.
- layer8 3y agoCompatibility is defined in terms of a contract between program and language implementation. If the program violates the contract by containing UB, then compatibility does not apply. Taking your argument, compilers couldn’t even add any benign optimization without breaking compatibility, because that would change the runtime of the affected code.
- agwa 3y ago> Compatibility is defined in terms of a contract between program and language implementation. If the program violates the contract by containing UB, then compatibility does not apply. Indeed, furthering my point that having UB in a language undermines backwards compatibility. > Taking your argument, compilers couldn’t even add any benign optimization without breaking compatibility, because that would change the runtime of the affected code. That does not follow from what I said.
- layer8 3y agoThe point is, you have to define compatibility with regards to what. Otherwise nothing can ever change. The purpose of the C standard is to provide that reference point, via its definition of what constitutes a conforming program and a conforming language implementation. You only get compatibility problems when you step out of that scope.