• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting from scalar to NSNumber*
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting from scalar to NSNumber*


  • Subject: Re: Converting from scalar to NSNumber*
  • From: Greg Parker <email@hidden>
  • Date: Fri, 27 Feb 2015 16:53:15 -0800

> On Feb 27, 2015, at 4:46 PM, Rick Mann <email@hidden> wrote:
>
>
>> On Feb 27, 2015, at 16:45 , Greg Parker <email@hidden> wrote:
>>
>>
>>> On Feb 27, 2015, at 4:28 PM, Rick Mann <email@hidden> wrote:
>>>
>>> I'm updating some older Core Data code in which I made liberal use of transient properties to map NSNumber* types to scalar types like uint32_t. In practice, this doesn't gain much, especially with boxing syntax, and it makes the Core Data classes messier (shadow attributes, etc.).
>>>
>>> The problem is, if I change an attribute's type to NSNumber*, and fail to modify every reference to that attribute, I often end up comparing pointers, not values:
>>>
>>>  @property (strong) NSNumber*		someAttribute;
>>>
>>>  if (obj.someAttribute > 42)
>>>
>>> which needs to become:
>>>
>>>  if (obj.someAttribute.integerValue > 42)
>>>
>>> I'd love an explicit warning for misuse of NSNumber*, but a pointer-integer comparison warning would be helpful. However, I don't see that among the available warnings in Xcode.
>>
>> Here's how to answer "is there a warning for X".
>> 1. Write a test file with the line of code that you want to be warned about.
>> 2. Compile that file with -Weverything which enables literally every warning supported by the compiler.
>> 3. If the compiler warns about the code then the diagnostic message will print the name of the warning flag, if any. Example:
>>   test.m:13:1: warning: control reaches end of non-void function [-Wreturn-type]
>> If it doesn't print a warning name then that warning is on all the time, I think.
>>
>> When I run a test of your code, I get a warning unconditionally. It's possible that my compiler is newer than yours; in your compiler there might be no warning, or there might be a warning behind some warning flag. Try it yourself.
>>
>> test.m:12:13: warning: ordered comparison between pointer and integer
>>     ('NSNumber *' and 'int')
>>   if (t.x > 42) printf("bigger");
>>       ~~~ ^ ~~
>
> Great suggestion. Some versions of GCC will also tell you the command-line option that controls the warning it's emitting. I wish clang did that.

Er, that's exactly what Clang does, when there is a command-line option. Example:
  test.m:13:1: warning: control reaches end of non-void function [-Wreturn-type]

Some of clang's warnings have no command-line option. Ordered comparison between pointer and integer appears to be one of them, at least in my version of the compiler.


--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

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


  • Follow-Ups:
    • Re: Converting from scalar to NSNumber*
      • From: Rick Mann <email@hidden>
References: 
 >Converting from scalar to NSNumber* (From: Rick Mann <email@hidden>)
 >Re: Converting from scalar to NSNumber* (From: Greg Parker <email@hidden>)
 >Re: Converting from scalar to NSNumber* (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Converting from scalar to NSNumber*
  • Next by Date: Re: Converting from scalar to NSNumber*
  • Previous by thread: Re: Converting from scalar to NSNumber*
  • Next by thread: Re: Converting from scalar to NSNumber*
  • Index(es):
    • Date
    • Thread