Re:
Re:
- Subject: Re:
- From: Jens Alfke <email@hidden>
- Date: Tue, 19 Jan 2016 10:48:40 -0800
> On Jan 19, 2016, at 10:11 AM, Aandi Inston <email@hidden> wrote:
>
> Thank you. The problem turned out to be a foolish mistake in the caller,
> but this has alerted me to the need for a systematic check of the
> conversion between BOOL and C integers.
The only thing likely to cause problems is if values other than 0 or 1 get assigned to a bool or BOOL, specifically values > 255. For example if you assign 256 to a BOOL it may end up as 0. This can happen if you refactor something like
if (count)
doSomething();
into
BOOL shouldDoSomething = (count);
…
if (shouldDoSomething)
doSomething();
Depending on the value of `count`, this can cause an overflow in the BOOL variable and give it an incorrect false value. The fix is to change the assignment to `(count != 0)`.
That being said, any Cocoa method that returns BOOL should be trustable to return only NO (0) or YES (1), so there shouldn’t be a need to do any extra checks on conversions.
—Jens
_______________________________________________
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: | |
| >[no subject] (From: Aandi Inston <email@hidden>) |
| >Re: (From: Jake Petroules <email@hidden>) |
| >Re: (From: Aandi Inston <email@hidden>) |