Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bool versus BOOL [duplicate]

Possible Duplicates:
Objective-C : BOOL vs bool
Is there any difference between BOOL and Boolean in Objective-C?

I noticed from the autocomplete in XCode that there is a bool and a BOOL in Objective-C. Are these different? Why are there two different kinds of bool?

Are they interchangeable?

like image 896
node ninja Avatar asked Jul 30 '10 22:07

node ninja


1 Answers

Yes they are different.

  • C++ has bool, and it is a true Boolean type. It is guaranteed to be 0 or 1 within integer context.
  • C99 has _Bool as a true Boolean type, and if <stdbool.h> is included, then bool becomes a preprocessor macro for _Bool (this header also defines true and false as preprocessor macros for 1 and 0 respectively).
  • Cocoa has BOOL as a type, but it is just a typedef for signed char. It can represent more values than just 0 or 1.
  • Carbon has Boolean as a type, but it is just a typedef for unsigned char. Like, Cocoa's BOOL it can represent more values than just 0 or 1.

For Cocoa and Carbon's “Boolean” types, they should be thought of as zero meaning false, and any non-zero value meaning true.

like image 65
dreamlax Avatar answered Sep 30 '22 16:09

dreamlax