• 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
BOOLs, definition of YES
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: BOOLs, definition of YES
      • From: Alexei Kosut <email@hidden>
    • Re: BOOLs, definition of YES
      • From: Andrew Pinski <email@hidden>
    • Re: BOOLs, definition of YES
      • From: Greg Hurrell <email@hidden>
    • Re: BOOLs, definition of YES
      • From: Stéphane Sudre <email@hidden>
    • Re: BOOLs, definition of YES
      • From: "Clark S. Cox III" <email@hidden>
  • Prev by Date: Retain count on controllers instantiated from nibs
  • Next by Date: Re: Stripping headers from embedded frameworks
  • Previous by thread: Retain count on controllers instantiated from nibs
  • Next by thread: Re: BOOLs, definition of YES
  • Index(es):
    • Date
    • Thread