More 'bool' weirdness
More 'bool' weirdness
- Subject: More 'bool' weirdness
- From: Jens Alfke <email@hidden>
- Date: Fri, 14 Jun 2013 15:58:31 -0700
OK, now I’ve hit a situation where the C99 ‘bool’ type is behaving weirdly. The following snippets all compile without errors or warnings:
bool foo = @“huh”;
bool foo = [NSMutableArray array];
bool x = &x;
static bool test(void) { return &test; }
In general it seems to be legal to assign any pointer or integer value to a LHS of type bool. But try this with BOOL or with any integer type, and you get an error. (If you try to assign a float to a bool, you do get an error about an implicit conversion.)
The only explanation I can think of is that when assigning to bool the compiler adds the same implicit “!= 0” test that it does if you put a non-bool expression in an if() or while() test … but that’s nuts. It’s totally not the right thing to do here; it’s more likely to just hide bugs (as it was doing in my 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