• 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: CriticalAlert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CriticalAlert


  • Subject: Re: CriticalAlert
  • From: Kurt Revis <email@hidden>
  • Date: Thu, 20 Dec 2001 14:02:10 -0800

On Thursday, December 20, 2001, at 01:36 PM, David Remahl wrote:

On the other hand, the following construct is one I use very often in Cocoa:

while( myStr = [myEnum nextObject] )
{
// do whatever
}

That would generate a warning, would it not? And I would have to manually
disable that warning.

Out of the box, gcc with Project Builder used to warn about this, if I remember correctly. Now that I check, it doesn't seem to do it anymore, which is unfortunate. (If you add -Wall to your compiler flags, you will get a warning: "suggest parentheses around assignment used as truth value".)

To avoid the warning, put an extra pair of parens around the expression. That is:

while ((myStr = [myEnum nextObject]))

This is a pretty well known idiom. (Like all idioms, it doesn't necessarily make much sense all by itself, though.)

--
Kurt Revis
email@hidden


  • Follow-Ups:
    • Re: CriticalAlert
      • From: Andrew Pinski <email@hidden>
    • Re: CriticalAlert
      • From: David Remahl <email@hidden>
References: 
 >Re: CriticalAlert (From: David Remahl <email@hidden>)

  • Prev by Date: Re: CriticalAlert
  • Next by Date: Re: Archiving objects without their owner[1]
  • Previous by thread: Re: CriticalAlert
  • Next by thread: Re: CriticalAlert
  • Index(es):
    • Date
    • Thread