Hello , What is the default value of BOOL in Objective-C?
+8
A:
There is no default value if you write
-(void)somemethod {
BOOL x; // <--- no default value
It is initialized to garbage.
However, for a BOOL
ivar, it will be initialized to NO
, as the whole instance is filled with 0 on initialization.
KennyTM
2010-05-27 09:05:41
Can you count on the non ivar BOOL to always be the same garbage? or is it different? (ie. I'm seeing it evaluate to the integer value of '2' in a NSlog statement)
bentford
2010-10-30 15:42:43
@bentford: No you can't.
KennyTM
2010-10-30 15:48:55