Re: Block variable syntax related question
Re: Block variable syntax related question
- Subject: Re: Block variable syntax related question
- From: Christiaan Hofman <email@hidden>
- Date: Mon, 12 Sep 2011 11:30:14 +0200
On Sep 12, 2011, at 10:31, Jean-Denis MUYS wrote:
>
> On 12 sept. 2011, at 09:41, Jean-Denis MUYS wrote:
>
>> I have been using "Boolean" instead of "BOOL" for a quite long, and haven't seen any adverse effect.
>>
>> Did I miss something?
>>
>> JD
>>
>
> A little search uncovered no less than 5 boolean types in OS X:
>
> _Bool : built-in
> BOOL: typedef signed char BOOL;
> bool: #define bool _Bool;
> Boolean: typedef unsigned char Boolean;
> boolean_t: typedef boolean_t int; (MACH kernel type)
>
> This is getting messy…
>
> JD
That just reflect the long history of OSX and everything it has been built upon from various corners of the C world (i.e. libraries). You should use the type that is appropriate for the context where you're using it. That means that in Cocoa you should always just use BOOL. Boolean is typically used in Core libraries such as CoreFoundation. In more primitive libraries some of the other types may be used. So when a function is declared with some particular type, try to use that type and not one of the others. This way you will not run into problems due to type, such as the one of the OP or other warnings (that may or may not be flagging a real problem) for instance due to signed/unsigned mismatch. When you're using Boolean, you're bound to get problems for signedness, because Cocoa uses signed char and Boolean is unsigned. One reason you may not have seen any problem is simply because you've turned on warnings such as these, or you may just be "lucky" never to have run into a problematic situation. But not seeing a problem does not mean it's OK, you just should always code defensively and use the correct type when there's no reason not to do.
Christiaan
_______________________________________________
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