Re: Logical and - second operator evaluated?
Re: Logical and - second operator evaluated?
- Subject: Re: Logical and - second operator evaluated?
- From: Sam Schapmann <email@hidden>
- Date: Mon, 02 Mar 2009 19:12:43 -0600
Have you checked that you have initialized the "timer" pointer to
nil? Like C, in Objective-C local variables (as opposed to instance
variables) are allocated on the stack frame and have unspecified
initial values. About the only thing you can count on for sure is
that the initial value is NOT nil (i.e. 0x0).
So, if your code is structured like the below snippet, then I would
expect BAD_ACCESS every time. That's because the first check is TRUE
(timer indeed is not nil), and the second check has the side effect of
attempting to invoke the isValid method at a memory location that is
1) random, and 2) certainly not even an Obj-C object. The BAD ACCESS
would result from the Obj-C runtime attempting to dereference the
timer pointer out to no-man's memory land.
Instance variables and static variables are initialized to bitwise
0's, so the above analysis would not apply in that case.
Just some thoughts.
-S
-(void)aMethod
{
NSTimer *timer;
if(timer!=nil && [timer isValid]) [timer invalidate];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden