|
|
|
|
|
by signa11
4519 days ago
|
|
huh :) have you actually tried doing that i.e. call the function with NULL params and see ? you will see a segfault.
anyways, rather than rely on vagaries of -O2 implementation on compilers, i would rather be explicit about it and just assert invariants... |
|
I'm not describing some optimization that you, the programmer, can do. I'm talking about what the compiler can (and will) do by assuming your code doesn't have undefined behavior.
In this particular case, the compiler recognizes that if the pointer is NULL, undefined behavior has already been invoked and it can therefore eliminate the check.
I recommend this series of posts on the LLVM blog: http://blog.llvm.org/2011/05/what-every-c-programmer-should-...