Re:Undefined behavior in C is a reading error
by tom_mellior on Friday May 21, 2021 @04:00PM
(#27239178)
I think you are misunderstanding the situation. Given code like:
if (!p) {
use(*p);
}
(given no previous knowledge about p) no compiler will remove the "if (!p)" part.
What people are complaining about is the opposite case:
use(*p);
/* The compiler reasons that if p == NULL, the program would have crashed by now,
so if we got here, p != NULL must hold. */
if (!p) { // the compiler can remove this branch
report_error();
}
What people are complaining about is the opposite case: