Hacker News new | past | comments | ask | show | jobs | submit login

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.




Nope, you're right - I meant to dereference the pointer, rather than just access it. D'oh!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: