• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: New C++ warning about comparing this==NULL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >New C++ warning about comparing this==NULL (From: Jens Alfke <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Jonathan Prescott <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Jens Alfke <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Doug Hill <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Roland King <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Doug Hill <email@hidden>)
 >Re: New C++ warning about comparing this==NULL (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: New C++ warning about comparing this==NULL
  • Next by Date: Re: New C++ warning about comparing this==NULL
  • Previous by thread: Re: New C++ warning about comparing this==NULL
  • Next by thread: Re: New C++ warning about comparing this==NULL
  • Index(es):
    • Date
    • Thread