Re: BOOLs, definition of YES
Re: BOOLs, definition of YES
- Subject: Re: BOOLs, definition of YES
- From: "Clark S. Cox III" <email@hidden>
- Date: Tue, 20 May 2003 10:23:47 -0400
On Tuesday, May 20, 2003, at 10:01 US/Eastern, 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.
That's simply not true, the C standard (and therefore ObjC) guarantees
that (!1 == 0) and (!0 == 1), so (!!1 == 1)
Give the following source:
//test.m
#include <Foundation/Foundation.h>
int main()
{
NSLog(@"!0 -> %d", !0);
NSLog(@"!1 -> %d", !1);
NSLog(@"!!0 -> %d", !!0);
NSLog(@"!!1 -> %d", !!1);
return 0;
}
[clarkg4:~] clarkcox% cc test.m -framework Foundation
[clarkg4:~] clarkcox% ./a.out
2003-05-20 10:23:14.978 a.out[2011] !0 -> 1
2003-05-20 10:23:14.981 a.out[2011] !1 -> 0
2003-05-20 10:23:14.995 a.out[2011] !!0 -> 0
2003-05-20 10:23:14.997 a.out[2011] !!1 -> 1
--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
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.