3 ms·
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 -
by signa11 13y 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...
- vinkelhake 13y agoI believe you got my comment completely bass ackwards. 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-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
- signa11 13y ago> 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. ah, makes sense thank you !
- EpicEng 13y ago*you will see a segfault* No, you will see undefined behavior. Undefined behavior doesn't mean "you get a segfault". That would be defined behavior.