I'm not sure this is correct. I think you are referring to the fact that if p was dereferenced before the NULL-check, then the compiler could optimize out the entire conditional statement.
This is true as dereferencing a NULL pointer is undefined behaviour, so is fair game for optimizations. The compiler may assume that NULL pointer dereferencing results in a trap/segfault and that the conditional can never be executed.
If I am wrong, and your example actually exhibits undefined behaviour, I would certainly love to learn why.
This is true as dereferencing a NULL pointer is undefined behaviour, so is fair game for optimizations. The compiler may assume that NULL pointer dereferencing results in a trap/segfault and that the conditional can never be executed.
If I am wrong, and your example actually exhibits undefined behaviour, I would certainly love to learn why.