|
|
|
|
|
by vyodaiken
3410 days ago
|
|
C programmers should be able to expect that "optimizations" will not transform program meaning. And because C is so low level, certain types of optimizations may be more difficult or impossible. If the pointer was explicitly set to NULL, the compiler can justifiably deduce the branch will not be taken but the deduction "if the programmer dereferenced the pointer it must not be NULL" is not based on a sound rule. In fact, the whole concept that the compiler can make any transformation it wants in the presence of UB is wacky. Optimization should always be secondary to correctness. |
|
If x is null, the program in #2 has no meaning. The only way to preserve its meaning is to assume x is not null.
> Optimization should always be secondary to correctness.
If x is null, the program in #2 has no correctness. The only way to salvage its correctness is to assume x is not null.