Re: omitting zero-test
Re: omitting zero-test
- Subject: Re: omitting zero-test
- From: Niko Matsakis <email@hidden>
- Date: Thu, 20 Feb 2003 12:14:53 -0500 (EST)
It might have something to do with the fact that
(2 & 2) == 2
((2 & 2) != 0) == 1
i.e., if some code relies on ticketOrder having a 0 or 1 then it
would do the wrong thing if the mask is testing bits other than 1.
niko
On Thu, 20 Feb 2003, 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.
>
>
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt
>
pantes anthropoi tou eidenai oregontai phusei
>
Subscribe to TidBITS! It's free and smart. http://www.tidbits.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.
_______________________________________________
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.