Re: BOOLs, definition of YES
Re: BOOLs, definition of YES
- Subject: Re: BOOLs, definition of YES
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 20 May 2003 16:27:07 +0200
On mardi, mai 20, 2003, at 16:01 Europe/Paris, Tom Sutcliffe wrote:
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
Uh ?
I might be missing something in your explanation but this code is
working fine:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
BOOL truetrue=YES;
BOOL falsefalse=NO;
truetrue=!truetrue;
falsefalse=!falsefalse;
if (truetrue==NO)
{
NSLog(@"!YES == NO");
}
if (falsefalse==YES)
{
NSLog(@"!NO == YES");
}
// insert code here...
[pool release];
return 0;
}
I also tested !!YES and it is YES.
_______________________________________________
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.