Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!pasteur!aldebaran!carlton From: carlton@aldebaran (Mike Carlton) Newsgroups: comp.sys.mac.programmer Subject: Re: Detecting Color Depth Message-ID: <8871@pasteur.Berkeley.EDU> Date: 14 Nov 90 01:25:01 GMT References: <1990Nov6.231358.18153@Neon.Stanford.EDU> <8068@adobe.UUCP> <21635@well.sf.ca.us> Sender: news@pasteur.Berkeley.EDU Reply-To: carlton@aldebaran.berkeley.edu (Mike Carlton) Distribution: na Organization: University of California at Berkeley Lines: 34 In article <21635@well.sf.ca.us> oster@well.sf.ca.us (David Phillip Oster) writes: >In article <8068@adobe.UUCP> hawley@adobe.UUCP (Steve Hawley) writes: >_>In article phils@chaos.cs.brandeis.edu (Phil Shapiro) writes: >_>>#define ScreenDepth(gdh) ((**((**gdh).gdPMap)).pixelSize) >_>>#define MaxColors(gdh) (1L< >_>>where gdh is a GDHandle (graphic device handle). > >_>Phil -- if your handle is not locked, isn't there a potential problem with >_>the order of evaluation of the dereferences --especially in a context that >_>may move memory? > >_>Steve Hawley >Steve, you should go back and reread Inside Macintosh and Knaster again. >There is NO WAY that a dereference of a pointer is going to move memory, >and no way that a string of simple dereferences is ever going to cause a >problem. >-- >-- David Phillip Oster - Note new signature. Old one has gone Bye Bye. >-- oster@well.sf.ca.us = {backbone}!well!oster But there is a potential problem if you use the macro on the LHS of an assignment with an unlocked handle, i.e. ScreenDepth(someGraphicHandle) = SomeCallThatMovesMemory(42); This is a classic gotcha for newcomers to Mac programming and is likely what Steve was referring to. For those that haven't seen this many times before, the problem is that the compiler is allowed to dereference the handle before making the procedure call, but the dereferenced value will be bogus if the call does have to move memory. Cheers, Mike Carlton, UC Berkeley Computer Science ~ carlton@ernie.berkeley.edu ...!ucbvax!ernie!carlton Manana