Re: Warning about comparison between pointer and integer
Re: Warning about comparison between pointer and integer
- Subject: Re: Warning about comparison between pointer and integer
- From: Dave Carrigan <email@hidden>
- Date: Wed, 16 Dec 2009 08:31:51 -0800
On Dec 16, 2009, at 8:18 AM, Eric E. Dolecki wrote:
> NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
>
> alarm1_hour = [prefs integerForKey:@"alarm1Hour"];
>
> if( alarm1_hour == NULL ){
>
> NSLog(@"alarm 1 hour is null" );
>
> }
-integerForKey returns a NSInteger. Comparing NSInteger to NULL (which is a declared as a pointer) is going to give you that warning. It certainly makes not sense to compare an integer to NULL.
> Should I use a temporary variable to check instead of the variable with the
> pointer? Or are these warnings okay to ignore?
Warnings are almost never ok to ignore. The compiler is trying to tell you that you're probably doing something wrong.
--
Dave Carrigan
email@hidden
Seattle, WA, USA
_______________________________________________
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