Re: Block variable syntax related question
Re: Block variable syntax related question
- Subject: Re: Block variable syntax related question
- From: Jens Alfke <email@hidden>
- Date: Fri, 09 Sep 2011 14:47:55 -0700
On Sep 9, 2011, at 12:38 PM, Bavarious wrote: In this particular case, the conditional operator promotes the second and third operands to int as specified in the C99 standard. This means that
[obj compare:@"foo"] == 0 ? YES : NO
is an int _expression_, not a BOOL one. The block variable has return type BOOL and the block literal has inferred return type int, hence the compiler error.
I think this stems from BOOL being merely a typedef for ‘signed char’, not a real type. This causes problems elsewhere too (for example, the sign bit means a one-bit wide BOOL bitfield member won’t work. That one’s fun to debug.)
Bit of a tangent, but as C’s had a native ‘bool’ type for a decade+ now, is there some reason Cocoa can’t switch to using it instead of BOOL? Like, make BOOL a typedef for bool? Or would that introduce too many compatibility problems? Or short of that, would there be a problem if an app were to switch to using bool in its own code?
—Jens |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden