Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!atheybey@PTT.LCS.MIT.EDU From: atheybey@PTT.LCS.MIT.EDU Newsgroups: comp.sys.amiga.tech Subject: Re: Double click detection? Message-ID: <8901301541.AA05371@PTT.LCS.MIT.EDU> Date: 30 Jan 89 15:41:53 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: atheybey@PTT.LCS.MIT.EDU Lines: 57 To: nntp-poster@PTT.LCS.MIT.EDU Repository: PTT Originating-Client: flower shimoda@infohh.rmi.de (Markus Schmidt) writes: %Four doubleclicks I use this logic: % %while (1) { % % imsg= GetMsg ( ... % if (imsg->Class= /* endevent */) % break; % % % if (imsg->Class==SELECTDOWN) % { % static Seconds= 0, % Micros= 0; % % if ((Seconds!=0 || Micros!=0) && % DoubleClick(Seconds,Micros, % imsg->Seconds, imsg->Micros)) { % % /* Your Stuff ... */ % % Seconds= Micros= 0; % } % else { % Seconds= imsg->Seconds; Micros= imsg->Micros; % } % } % %} % %Please notice that ReplyMsg is not handled. I just hacked that down %online. % %.-----------------------------------------------------------------. %| shimoda@rmi.de `---' The last remaining adventure | %| shimoda@gopnbg.UUCP |O o| since there are no more tigers: | Please correct me if I am wrong, but doesn't this code fragment contain two Bad Things? No Guru has yet responded, so I thought I would take a shot at sticking my foot in my mouth. It busy-waits. There is no call to Wait(), or WaitPort() before the GetMsg(). Even if you are busy-waiting only while looking for double clicks, you shouldn't. GetMsg() will return NULL if no message has yet arrived. With the various 'if (imsg-> ... )' tests, you are then indirecting through address 0, which while not necessarily fatal, is sloppy and will quite likely break on any system with memory protection (unless it's a VAX :-). Even if you do call Wait(), you should not depend on GetMsg() returning something non-NULL. --------------------------------------------------------------------------- Andrew Heybey, atheybey@ptt.lcs.mit.edu Room 509, 545 Technology Square Advanced Network Architecture Group Cambridge, MA 02139 MIT Laboratory for Computer Science (617) 253-6011 ---------------------------------------------------------------------------