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

Re: Unnecessary Boolean Warning


  • Subject: Re: Unnecessary Boolean Warning
  • From: Roland King <email@hidden>
  • Date: Thu, 04 Aug 2011 09:32:22 +0800

The C99 spec I can find on the net has 6.5.13 (3) and (4).

3. The && operator shall yield 1 if both of it's operands compare unequal to 0; otherwise it yields 0. The result has type int.

4. Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the firt operand compares equal to 0, the second operand is not evaluated.

To my reading, and unless I have a totally bogus spec, that makes exactly the guarantee Jean-Daniel claims.



On Aug 4, 2011, at 8:56, Graham Cox <email@hidden> wrote:

>
> On 04/08/2011, at 1:52 AM, Jean-Daniel Dupas wrote:
>
>> One important difference for instance is that if you write if (a() & b()), both a() and b() will always be executed, while if you write if (a() && b()), b() will be executed only if a() is true.
>
>
> The C language doesn't make any guarantees about that. While this optimisation is to be expected, the order of execution (left to right) and the optimisation (b not executed) is implementation dependent.
>
> This is a classic question for coding job interviews.
>
> --Graham
>
>
> _______________________________________________
>
> 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
_______________________________________________

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: 
 >Unnecessary Boolean Warning (From: Dale Miller <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Charles Srstka <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Dale Miller <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Scott Ribe <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Thomas Davie <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Scott Ribe <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Thomas Davie <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Unnecessary Boolean Warning (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Unnecessary Boolean Warning
  • Next by Date: Correct way to use contextInfo with ARC
  • Previous by thread: Re: Unnecessary Boolean Warning
  • Next by thread: Re: Unnecessary Boolean Warning
  • Index(es):
    • Date
    • Thread