• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: BOOLs, definition of YES
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: BOOLs, definition of YES
      • From: Tom Sutcliffe <email@hidden>
References: 
 >BOOLs, definition of YES (From: Tom Sutcliffe <email@hidden>)

  • Prev by Date: Re: try statement
  • Next by Date: Re: NSRectFill not supporting compositing?????
  • Previous by thread: BOOLs, definition of YES
  • Next by thread: Re: BOOLs, definition of YES
  • Index(es):
    • Date
    • Thread