• 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: nil pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nil pointers


  • Subject: Re: nil pointers
  • From: Rob Ross <email@hidden>
  • Date: Tue, 11 Jul 2006 09:40:51 -0700



On Jul 11, 2006, at 9:20 AM, Uli Kusterer wrote:


window theWindow = [new window] button theBtn [theWindow mapToScreen] theBtn = [new buttonIn: theWindow]

Now, when someone later inserts another call after mapToScreen and accidentally makes use of theBtn, he'll access an invalid pointer (in this case that'd be obvious, but if this was a more complex function, it might be harder to spot). So, what people do is set theBtn to NULL (or NIL, or whatever) so you either (in plain C) get an access fault right away, or (in Cocoa) wonder why your message doesn't stick and see the variable is still NIL.

Isn't it better to find out right away if your method call fails? If you set theBtn = nil and pass a message to it, it's true that nothing "bad" will happen, but nothing "good" happens either. It seems this would be harder to debug than if you just got a stack trace right at the point of access, so you would know that you were trying to pass a message to an uninitialized reference.


Rob




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: nil pointers
      • From: Andreas Mayer <email@hidden>
    • Re: Re: nil pointers
      • From: "Shawn Erickson" <email@hidden>
References: 
 >nil pointers (From: "Adam Johnson" <email@hidden>)
 >Re: nil pointers (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: NSStatusItem in Carbon
  • Next by Date: Re: View disappears with NSViewAnimation
  • Previous by thread: Re: nil pointers
  • Next by thread: Re: Re: nil pointers
  • Index(es):
    • Date
    • Thread