Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.sys.apple2    |    Discussion about Apple II micros    |    56,720 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 56,194 of 56,720    |
|    Dirk Froehling to All    |
|    Re: Why and wmTaskData4 ?    |
|    08 Jun 23 13:17:02    |
   
   From: dirk.froehling@freenet.de   
      
   Am 02.06.23 um 19:15 schrieb Tom Thumb:   
   > On Thursday, June 1, 2023 at 8:33:08 PM UTC-4, Tom Thumb wrote:   
   >> On Thursday, June 1, 2023 at 2:05:06 PM UTC-4, stephen...@gmail.com wrote:   
   >>> On Thursday, June 1, 2023 at 11:25:59 AM UTC-5, Tom Thumb wrote:   
   >>>> On Wednesday, May 31, 2023 at 3:17:30 PM UTC-4, Tom Thumb wrote:   
   >>>>> Mike Westerfield's "Toolbox Programming in C" contains a routine:   
   >>>>>   
   >>>>> void HandleControl (void)   
   >>>>> {   
   >>>>> if ((myEvent.wmTaskData4 & 0xFFFF8000) == 0)   
   >>>>> switch (myEvent.wmTaskData4) {   
   >>>>>   
   >>>>> ...   
   >>>>>   
   >>>>> I can find no explanation for doing this. I believe it's just testing if   
   any of the bits 17 - 31 have been set to one?   
   >>>>>   
   >>>>> I'd be grateful if someone would explain why this is being done. I   
   imagine I've missed something there or the IIgs Reference Manuals.   
   >>>> Oh, it's checking to see if wmTaskData4 is less than 32768   
   >>> Yes, that's correct. In this case wmTaskData4 holds a control ID value,   
   and all the control IDs that the code wants to check for are less than 32768.   
   The "if" check is OK, but it's not really necessary, since the code could just   
   check for the control    
   IDs of interest via the "switch".   
   >>>   
   >>> I suspect the "if" check is there because the code was originally written   
   in Pascal for the Toolbox Programming in Pascal course and then later   
   translated to C. The "case" statement in ORCA/Pascal can only handle values up   
   to 32767, making a check    
   like this necessary, but the "switch" statement in C does not have the same   
   limitation.   
   >>>   
   >>> --   
   >>> Stephen Heumann   
   >> Ahh, thank you very much.   
   >   
   > May I ask though; why go about it this way: if ((myEvent.wmTaskData4 &   
   0xFFFF8000) == 0) rather than: if(myEvent.wmTaskData4 <= 32767) ?   
   >   
   > is there a reason? or just a choice?   
   >   
      
   It is easier to read. :)   
      
   No, really. 32767 is meaningless in that context. wmTaskData4 contains a   
   bunch of seperate settings coded as bits, not a single number.   
      
   0xFFFF8000 is 1111 1111 1111 1111 1000 0000 0000 0000 in binary form,   
   and by ANDing wmTaskData4 with this number, you say "I am only   
   interested in the upper 17 bits, ignore the lower bits."   
   The IF condition then means "If none of the settings in the upper 17   
   bits is set, do the following."   
      
   Dirk   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca