Re: omitting zero-test
Re: omitting zero-test
- Subject: Re: omitting zero-test
- From: Chris Ryland <email@hidden>
- Date: Thu, 20 Feb 2003 13:18:03 -0500
Matt--
On Thursday, February 20, 2003, at 11:55 AM, matt neuburg wrote:
This is an elementary question, but it sure caught me flat-footed so I
thought I'd ask. Why doesn't this work properly?
BOOL ticketOrder =
([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask);
It only works if I explicitly test for zero:
BOOL ticketOrder =
(([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0);
I'm one of those lazy C coders who never in his life has written !=0
or !=nil, so I was very surprised by this. Does it have something to
do with the fact that the integer returned by modifierFlags is
unsigned? Thx - m.
Or maybe ticketOrder is indeed non-zero after initialization, but if
you test it against YES or NO (or pass it to some other routine
expecting YES or NOT) it's not equal to either?
Still, a later "if (ticketOrder)" should succeed, unless, as Nicholas
suggests, a BOOL is an eight-bit quantity, and if NSAlternateKeyMask >
0xff, you're losing information when assigning to the BOOL.
(From a Cocoa newbie
Cheers!
--Chris Ryland / Em Software, Inc. / www.emsoftware.com
_______________________________________________
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.