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: Keary Suska <email@hidden>
- Date: Fri, 24 Feb 2012 10:36:51 -0700
On Feb 24, 2012, at 7:50 AM, Oleg Krupnov wrote:
> An interesting question. The following samples are equivalent in terms
> of compiled code, but which one is more correct from the language's
> point of view?
>
> self = [super init];
> if (self)
> {
> }
> return self;
>
> self = [super init];
> if (self != nil)
> {
> }
> return self;
It may really boil down to a stylistic issue, but I believe that the "self != nil" syntax is the most canonical.
> I also heard that generally speaking NULL is not necessarily always
> equal to 0 on all architectures.
I don't believe this is the case. There can be funny issues with BOOL types, such that BOOL == YES is an inadvisable construct, since your BOOL could be an integer of any value.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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