Re: error in using NSNumber's numberWithInt: method not flagged
Re: error in using NSNumber's numberWithInt: method not flagged
- Subject: Re: error in using NSNumber's numberWithInt: method not flagged
- From: Kyle Sluder <email@hidden>
- Date: Sun, 09 Jun 2013 13:32:50 -0700
On Jun 9, 2013, at 1:26 PM, Boyd Collier <email@hidden> wrote:
>
> Quite by chance, I stumbled on to what seems to be an error that ought to be caught by the compiler but wasn't. Here's an example:
>
> NSNumber *testNumber = [NSNumber numberWithInt:5];
> int testInt = (int)testNumber;
>
> […snip…]
>
> Should I file a bug report or is this a well-known anomaly that I've just come across?
Sitting on a runway right now, so I can't double-check the C spec, but I believe this is a consequence of C's use of integers for truth types.
A pointer must be convertible to integer type, because it can be used in the form `if (expressionOfPointerType)`. It follows that casting to int must also be allowed. I'm not sure what the spec says about the actual value of the result.
--Kyle Sluder
_______________________________________________
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