Re: nil pointers
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