BOOLs, definition of YES
BOOLs, definition of YES
- Subject: BOOLs, definition of YES
- From: Tom Sutcliffe <email@hidden>
- Date: Tue, 20 May 2003 15:01:48 +0100
Sorry this is a minor Java/C types whinge but I'm interested in how
others approach this.
Coming from Java I'm used to having booleans as a distinct type, and
for the ! operator to work correctly on them. So in Obj-C I was
surprised to find that because of YES and NO being defined as 1 and 0,
YES doesn't equal !!YES.
I'm therefore interested in how best to go about inverting a BOOL
variable. I stuck with
flag = (flag ? NO : YES);
// flag = 1 - flag would also work but is even less clear
but I'm sure there must be a better way, that is shorter. I'd like to
be able to do flag = !flag as in java. Out of interest I tried defining
YES to be 0xFFFFFFFF
#ifdef YES
#undef YES
#endif
#define YES (BOOL)-1
// YES is now the same as !!YES
which seems to work in my test prog but probably wouldn't if I had to
pass a BOOL outside of my code. Is there a better way to invert a BOOL,
that more closely matches the semantic meaning of true and false? I
suppose I'm just doomed to have to think of BOOLs as ints in disguise.
And while we're here, is there any good reason why YES isn't defined as
the bitwise inversion of NO?
Thanks,
Tom
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.