Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucdavis!iris!lim From: lim@iris.ucdavis.edu (Lloyd Lim) Newsgroups: comp.sys.mac.programmer Subject: Re: "TN.248.DAs in Need of Time" in need of proofreader. Keywords: Sloppy, careless, wrong. Message-ID: <5281@ucdavis.ucdavis.edu> Date: 8 Sep 89 11:01:55 GMT References: <15462@dartvax.Dartmouth.EDU> <34579@apple.Apple.COM> Sender: uucp@ucdavis.ucdavis.edu Reply-To: lim@iris.ucdavis.edu (Lloyd Lim) Organization: U.C. Davis - Department of Electrical Engineering and Computer Science Lines: 69 In article <34579@apple.Apple.COM> pvh@Apple.COM (Pete Helme) writes: > >Unfortunately for me, I used THINK C (not MPW C) to test the statement: > > dce->dCtlFlags ^= dNeedTime; > dce->dCtlFlags |= dNeedTime; > >which THINK C compiles to: > > BCHG #5,4(A0) > BSET #5,4(A0) > >BSET #5,4(A0) is OK for what we want since it's the high byte we're changing, >but it's not correctly compiled as far as the operators are concerned. >THINK C actually included stuff like dce->dCtlFlags |= dNeedTime in >their old samples I believe. That's why I probably left it that way. >BCHG 5,4(A0) is just plain wrong. A pox on me and my 4 slice toaster. > > >FYI, THINK C compiled the following lines: > > dce->dCtlFlags &= ~(1 << (dNeedTime + 8)); > dce->dCtlFlags |= (1 << (dNeedTime + 8)); > >to: > > BCLR #0,4(A0) > BSET #0,4(A0) > >Huh? If you look through the THINK C header files, you'll see what's going on. Inside Mac says dNeedTime is 5 while THINK C has #define dNeedTime 0x2000. Earle's code is correct for the Inside Mac values. The correct code for THINK C is: dce->dCtlFlags &= ~dNeedTime; dce->dCtlFlags |= dNeedTime; The output of the THINK C compiler (the resulting bit instructions) can be explained by something I heard on the net sometime somewhere (probably in a dream. I remember the statement that the THINK C compiler optimizes bit operations with single bit masks to bit instructions. Is this true, Rich? BTW, I was stuck for an hour today with code that essentially looked like this once you evaluated all the #defines and stuff: switch (x) { 0: /* */ break; 1: /* */ break; default: Debugger(); break; } For the life of me, I couldn't see what was wrong. Then I noticed the missing cases. Arrrggghhh! Sometimes I wonder why these things compile. TMON wasn't too enlightening since the code for the fake cases was in there and it looked okay. +++ Lloyd Lim Internet: lim@iris.ucdavis.edu (128.120.57.20) Compuserve: 72647,660 US Mail: 146 Lysle Leach Hall, U.C. Davis, Davis, CA 95616