Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!dayton!joe From: joe@dayton.UUCP (Joseph P. Larson) Newsgroups: comp.sys.amiga.tech Subject: Re: Ultimate Wait-GetMsg strategy (?) Message-ID: <6402@dayton.UUCP> Date: 13 Feb 89 15:04:50 GMT References: <8902100658.AA16049@postgres.Berkeley.EDU> <6777@polya.Stanford.EDU> Reply-To: joe@dayton.UUCP (Joseph P. Larson) Organization: Dayton-Hudson Dept. Store Co. Lines: 51 Matt Dillon responded to someone's code fragment listed below. He didn't like it... This posting is my response to Tomas' response to Matt's response. In some article, rokicki@polya.Stanford.EDU (Tomas G. Rokicki) writes: >>:Now I think I got it: >>:while (1) { >>: while (!(imsg= GetMsg(win->UserPort))) >>: Wait (1<UserPort->mp_SigBit); >>: select imsg->Class and break when ended >>:} > >This is *perfectly* fine. while(1)/break is a general looping >construct. while(notquit) is fine, too. > >> Yes, that's probably the worse way to do it. > >.... Secondly, his code *works*, and the >coding style is one I happen to agree with. Matter of taste, Matt. > ..... >Sorry for the flaming tone of this article, Matt. I just hate people >cutting down other people's coding style like that. I think what happened is that Matt's response might have been a little fast. I don't want to put words in Matt's mouth, but I almost posted the same message until I looked at the code a little better. The second time around I noticed the "!" on the "while" line. It makes for a very big difference in how you read the code! Personally, I don't like using a "!" in this case for two reasons: 1. It can lead to the problem I just described. "!" just isn't as noticable as one might like to indicate "I'm going to do this if this DOESN'T happen." 2. GetMsg() returns a pointer. "!" is a logic operator. Just because NULL happens to be zero doesn't mean that "!" is the correct way of checking for it. Good coding practice (as outlined by people with more letters after their name than I have) suggest you check pointers against NULL. If nothing else, it help assures better portability. (There are machines where "!" won't work. As of 2 years ago, Sperry's 1100 version of C required 1 36-bit word for the address and another byte for an offset in the 36-bit word that a pointer points to. "!" on pointers wouldn't work....) However, on the Amiga, the above code fragment will work (assuming you're only grabbing messages from one UserPort). -J -- When you fall on your head do you land on your feet? UUCP: rutgers!dayton!joe (Feed my Dayton Hudson Department Store Company ATT : (612) 375-3537 picture Joe Larson/MIS 1060 (standard disclaimer...) collection) 700 on the Mall Mpls, Mn. 55402