Re: [Obj-C] if (self) vs. if (self != nil)
Re: [Obj-C] if (self) vs. if (self != nil)
- Subject: Re: [Obj-C] if (self) vs. if (self != nil)
- From: Scott Ribe <email@hidden>
- Date: Fri, 24 Feb 2012 16:26:09 -0700
On Feb 24, 2012, at 12:47 PM, Kyle Sluder wrote:
> But I'm not sure the integer conversion is necessarily relevant. The
> semantics of the if statement are defined by §6.8.4.1 ¶2: "the first
> substatement is executed if the expression compares unequal to 0." It
> is left unspecified if '0' is an integer constant expression or an
> arithmetic expression with an integer value of zero. If the former,
> then the pointer is compared against the null pointer constant per
> §6.3.2.3 ¶4. If the latter, the pointer is converted to integer per
> implementation-defined behavior and the comparison is performed, which
> might itself result in undefined behavior per §6.5 ¶5 since the
> conversion is not guaranteed to produce a value within range of any
> integer type.
Thing is: if(foo) is equivalent to if(foo != 0), which I think results in 0 being treated as a pointer, not the pointer being cast to int, anyway if if(foo) could fail, so could if(foo != 0)... Also I think "Except as previously specified..." covers the case that NULL pointers convert to int 0...
--
Scott Ribe
email@hiddenhttp://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
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