• 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: Tom Sutcliffe <email@hidden>
  • Date: Tue, 20 May 2003 17:44:13 +0100

Yes sorry everybody this was definitely my mistake. I was confusing logical and bitwise negation (or rather, which did what). Many thanks for pointing it out before I *really* started to get confused :)

For the record ! does exactly what I want and I was thinking of ~. I missed another bug in my code which sent me hurtling towards the wrong conclusion about why everything wasn't working. I'll go and hide now.

Cheers,

Tom

On Tuesday, May 20, 2003, at 03:23 pm, Clark S. Cox III wrote:


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.

References: 
 >Re: BOOLs, definition of YES (From: "Clark S. Cox III" <email@hidden>)

  • Prev by Date: PB error opening - didn't find classname for 'isa' key
  • Next by Date: Re: How to stop Classic launching iTunes? (Cocoa & Applescript)
  • Previous by thread: Re: BOOLs, definition of YES
  • Next by thread: Re: BOOLs, definition of YES
  • Index(es):
    • Date
    • Thread