> In the printf example, the compiler could trivially emit an error saying "NULL check on p after dereference of p"
If you know that p is not NULL, the code is just fine. The compiler has to compile it.
If you know that p is not NULL, the code is just fine. The compiler has to compile it.
Kent Dybvig's classic response to "Who writes that kind of code?" is "Macros do." Inlining has much the same effect as macros.
These dummy tests can happen if you have a lot of macros for example. It still valid C code as long as p is not NULL. A compiler generating an error on this particular example wouldn't be a correct C compiler.
The compiler can reject this code if it can prove that p can be NULL, but in many case that's impossible at compile time.
I agree that a warning would be nice though.
edit: clarity.