• 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: NSAssert and Unused Variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAssert and Unused Variable


  • Subject: Re: NSAssert and Unused Variable
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 2 Apr 2008 17:30:27 -0700


On 2 Apr '08, at 5:03 PM, Richard Somers wrote:

The NSAssert complies out in the release configuration by using the preprocessor macro NS_BLOCK_ASSERTIONS. This results in a warning: unused variable "error".
Do most programmers turn off the unused variable warnings or do something else to get this to work.

I don't think most people use NS_BLOCK_ASSERTIONS; instead they leave the assertion checks in the shipping product. Every Cocoa app (and framework) that Apple ships has assertions enabled, as far as I know.


This does add a little bit of overhead (code size more than performance.) But it makes the app more resilient to unexpected failures — a bug is more likely to result in an error alert than a crash. It also makes bugs reported by users more informative, as you can glean a lot more information from an exception message than you can from a crash log. (Especially if you add a bit of code to display exception backtraces.)

But I'm not going to tell you not to compile the assertions out; it's a matter of individual judgment. I seem to recall a pragma or macro that can be used to tell the compiler "I know this variable is unused, don't complain about it", though I don't remember the details...

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: NSAssert and Unused Variable
      • From: Chris Suter <email@hidden>
References: 
 >NSAssert and Unused Variable (From: Richard Somers <email@hidden>)

  • Prev by Date: Re: NSAssert and Unused Variable
  • Next by Date: Re: Subviews of a borderless window - autoresizing mask does not work for me
  • Previous by thread: Re: NSAssert and Unused Variable
  • Next by thread: Re: NSAssert and Unused Variable
  • Index(es):
    • Date
    • Thread