Re:The Problem with Friendly C
by scott_s on Wednesday December 23, 2015 @10:20PM
(#10786927)
The problem, as Regehr (the author of this submission) has pointed out many times before, is more subtle than that. Because certain behavior is considered undefined, compilers are allowed to assume the code it is compiling is well defined, and optimize accordingly. That can cause simple bugs to have mysterious effects. For example:
Obviously that code is wrong; I should check for NULL before using a. But because I dereferenced a, the compiler can assume a must not be NULL, and just removes the null check as dead code. This scenario has caused problems in the kernel, and made bad bugs even worse.
[ Parent
| on HN ]
But the compiler could just as well emit a warning "useless NULL comparison" instead of blithely assuming that the programmer intentionally wrote a book expression. That wouldn't handle every case of UB, but would handle many.
Re:The Problem with Friendly C
by superuser2 on Thursday December 24, 2015 @01:45AM
(#10787369)
A warning on removed dead code isn't helpful because dead come is legitimately removed all the time. No one would ever heed it.