FROM : John Stiles
DATE : Fri Aug 31 19:02:09 2007
I *think* that the C spec doesn't specify the result of a boolean
expression other than "zero means false, nonzero means true." So from
a "compliance with the spec" standpoint, the first version might
return different results from the second version.
In practice, I've never seen a compiler which didn't generate 1 for a
true result when computing a boolean expression. And YES == 1.
I am sure that an exception exists out there somewhere, on some weird
hardware/compiler combination, where a true boolean expression
returns a value other than one, but I doubt you will see this
becoming an issue in your code if you keep using standard tools.
On Aug 30, 2007, at 11:19 PM, Charles Steinman wrote:
>
> --- Eyal Redler <<email_removed>> wrote:
>
>> Hi,
>>
>> I'm not sure where and when but I recall reading
>> something about ObjC
>> BOOL type values YES and NO not being the same as
>> whet a boolean
>> expression might produce.
>> I can't recall the exact details but there was some
>> kind of gotcha
>> related to this. For example, the expression
>>
>> BOOL myBool=(myInt==1);
>>
>> might set myBool differently then
>>
>> BOOL myBool=(myInt==1)?YES:NO;
>
> The two expressions are equivalent. YES is defined as
> (BOOL)1, while NO is defined as (BOOL)0.
>
>>
>> Or maybe it was that
>>
>> if (myBool)
>> [foo bar];
>>
>> will perform differently then
>> if (myBool==YES)
>> [foo bar];
>
> I wouldn't say it will work differently, but it might.
> There's no language constraint that says a BOOL can
> only be set to YES or NO (though I wouldn't
> intentionally set a BOOL to some other value). So if a
> method returns a nonzero value that is not 1, if
> (myBool) will evaluate to true while if (myBool ==
> YES) will evaluate to false.
>
> Cheers,
> Chuck
>
>
>
> ______________________________________________________________________
> ______________
> Got a little couch potato?
> Check out fun summer activities for kids.
> http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities
> +for+kids&cs=bz
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/jstiles%
> 40blizzard.com
>
> This email sent to <email_removed>
DATE : Fri Aug 31 19:02:09 2007
I *think* that the C spec doesn't specify the result of a boolean
expression other than "zero means false, nonzero means true." So from
a "compliance with the spec" standpoint, the first version might
return different results from the second version.
In practice, I've never seen a compiler which didn't generate 1 for a
true result when computing a boolean expression. And YES == 1.
I am sure that an exception exists out there somewhere, on some weird
hardware/compiler combination, where a true boolean expression
returns a value other than one, but I doubt you will see this
becoming an issue in your code if you keep using standard tools.
On Aug 30, 2007, at 11:19 PM, Charles Steinman wrote:
>
> --- Eyal Redler <<email_removed>> wrote:
>
>> Hi,
>>
>> I'm not sure where and when but I recall reading
>> something about ObjC
>> BOOL type values YES and NO not being the same as
>> whet a boolean
>> expression might produce.
>> I can't recall the exact details but there was some
>> kind of gotcha
>> related to this. For example, the expression
>>
>> BOOL myBool=(myInt==1);
>>
>> might set myBool differently then
>>
>> BOOL myBool=(myInt==1)?YES:NO;
>
> The two expressions are equivalent. YES is defined as
> (BOOL)1, while NO is defined as (BOOL)0.
>
>>
>> Or maybe it was that
>>
>> if (myBool)
>> [foo bar];
>>
>> will perform differently then
>> if (myBool==YES)
>> [foo bar];
>
> I wouldn't say it will work differently, but it might.
> There's no language constraint that says a BOOL can
> only be set to YES or NO (though I wouldn't
> intentionally set a BOOL to some other value). So if a
> method returns a nonzero value that is not 1, if
> (myBool) will evaluate to true while if (myBool ==
> YES) will evaluate to false.
>
> Cheers,
> Chuck
>
>
>
> ______________________________________________________________________
> ______________
> Got a little couch potato?
> Check out fun summer activities for kids.
> http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities
> +for+kids&cs=bz
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/jstiles%
> 40blizzard.com
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Eyal Redler | Aug 31, 07:30 | |
| Charles Steinman | Aug 31, 08:19 | |
| John Stiles | Aug 31, 19:02 | |
| Clark Cox | Aug 31, 20:00 | |
| Clark Cox | Aug 31, 20:07 | |
| Charles Steinman | Aug 31, 20:28 | |
| Eyal Redler | Sep 1, 07:34 | |
| Scott Ribe | Sep 6, 05:03 | |
| glenn andreas | Sep 6, 05:24 | |
| John Stiles | Sep 6, 05:32 | |
| Clark Cox | Sep 6, 07:15 | |
| Wincent Colaiuta | Sep 6, 12:47 | |
| j o a r | Sep 6, 13:24 | |
| Scott Ribe | Sep 6, 16:02 |






Cocoa mail archive

