Re: New C++ warning about comparing this==NULL
Re: New C++ warning about comparing this==NULL
- Subject: Re: New C++ warning about comparing this==NULL
- From: Marco S Hyman <email@hidden>
- Date: Wed, 02 Dec 2015 22:22:03 -0800
On Dec 2, 2015, at 9:28 PM, Jens Alfke <email@hidden> wrote:
>
> It’s not a weird situation at all. Something returns you an object pointer. You call a method on that object. But the pointer you got happens to be NULL. Ergo, you’ve just called a method on a NULL pointer.
> Widget *w = factory.getCurrentWidget();
> Paint *p = w->getPaint();
> If the currentWidget is NULL, the second line does this.
I’d argue that if getCurrentWidget() can return a null you should never invoke w->getPaint() without first checking that w is not null. Isn’t it a compiler implementation detail that w->getPaint under the covers turns into getPaint(w)?
w->getPaint is in effect dereferencing a null w. That fits the quoted portion of the standard.
At least that is how I see it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden