• 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: [commentary] The value of warnings [was: Re: A Data Object in Cocoa]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa]


  • Subject: Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa]
  • From: Andrew Farmer <email@hidden>
  • Date: Sat, 10 Jan 2009 16:21:28 -0800

On 10 Jan 09, at 08:46, Michael Ash wrote:
Just to pick a nit, this depends greatly on what the warning is about.
A lot of warnings are actually about code whose behavior is fully
specified by the standard but which is still considered to be iffy.
For example, writing if(a = b) will generate a warning under -Wall but
its behavior is fully specified and cannot change in any conforming
compiler.

However it's still a good idea to fix them, and many warnings *are*
about code whose behavior could change.

Excellent point. As you mention, though, it's usually best to just work around these sorts of warnings (in this case, with an extra set of parentheses), as it's quite common that this sort of code *is* a mistake on the part of the author. :)


On 10 Jan 09, at 15:20, Sean McBride wrote:
Then there is the annoying situation of a warning that is in general
very useful, but sometimes warns in cases where you really don't want it to.


My favourite example is when Cocoa has two methods with the same name
that return different types. Like -(NSRect)frame vs -(CGRect)frame, or -
(id)window vs -(NSWindow*)window, or -(NSUInteger)count vs - (size_t)count.


For example:

	NSArrayController* controller = nil;
	NSUInteger c = [[controller arrangedObjects] count];

gives "warning: multiple methods named '-count' found" :(

You can silence this one by casting the return value of the inner method to a more specific type. In this case, the fix is:


  NSUInteger c = [(NSArray *)[controller arrangedObjects] count];

As Kyle Sluder mentions, this warning has the potential to generate incorrect code, so the warning is entirely appropriate.
_______________________________________________


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


References: 
 >[commentary] The value of warnings [was: Re: A Data Object in Cocoa] (From: Stuart Malin <email@hidden>)
 >Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa] (From: "I. Savant" <email@hidden>)
 >Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa] (From: Andrew Farmer <email@hidden>)
 >Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa] (From: "Michael Ash" <email@hidden>)
 >Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa] (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa]
  • Next by Date: CALayer, CATextLayer, and inheritance . . .
  • Previous by thread: Re: [commentary] The value of warnings [was: Re: A Data Object in Cocoa]
  • Next by thread: Pasting into another app
  • Index(es):
    • Date
    • Thread