Null Pointer Dereferencing Causes Undefined Behavior

We have unintentionally raised a large debate recently concerning the question of whether it is legal in C/C++ to use the &P->m_foo expression with P being a null pointer. The programmers’ community divided into two groups. The first claimed with confidence that it isn’t legal, while the others were as sure that it is. Both parties gave various arguments and links, and we thought that at some point we had to make things clear. For that purpose, we contacted Microsoft MVP experts, and the Visual C++ Microsoft development team communicating through a closed mailing list. They helped us to prepare this article and now everyone interested is welcome to read it. For those who can’t wait to learn the answer: That code is NOT correct.

image1 Continue reading