On 19/02/16 12:04, Petr Spacek wrote:

Could you elaborate on this, please?

What is wrong with
     if (ptr != NULL)
?

What standard says that it is wrong?

That isn't what's wrong. What is wrong is the method call that got you there. You have a method like this:

void foo()
{
  if (this != NULL) ...
}

and then you invoke it with a null pointer:

xxx->foo();

and it is that call that is not allowed by the standard when xxx is null.

So the compiler is allowed to assume that this will never be null in a method, because calling a method on a null pointer is not allowed, so it can just remove your null test in the method.

Then when you do call it on a null pointer you crash because the method is not doing the null test and just tries to access members of the object.

Tom

--
Tom Hughes (t...@compton.nu)
http://compton.nu/
--
devel mailing list
devel@lists.fedoraproject.org
http://lists.fedoraproject.org/admin/lists/devel@lists.fedoraproject.org

Reply via email to