Path: utzoo!news-server.csri.toronto.edu!rutgers!sun-barr!apple!apple.com!rmh From: rmh@apple.com (Rick Holzgrafe) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C Agony! Message-ID: <12454@goofy.Apple.COM> Date: 8 Mar 91 23:12:34 GMT References: <1991Mar7.063549.14081@dartvax.dartmouth.edu> Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 27 In article <1991Mar7.063549.14081@dartvax.dartmouth.edu> sean@eleazar.dartmouth.edu (Sean P. Nolan) writes: > if (!((**hclusterNew).prgbiasstruct = > (BIASSTRUCT**) NewHandle(NumNodes * sizeof(BIASSTRUCT)))) With some compilers, this can fail. A simplified example is: (**h).f = NewHandle (20); If the handle h is not locked, and if the compiler evaluates **h before calling NewHandle, then the value of **h may become incorrect when NewHandle shuffles the heap. There are three possible solutions. (1) Lock the handle. (2) Use a temporary variable: Handle theNewHandle = NewHandle (20); (**h).f = theNewHandle; or (3) some compilers avoid the whole issue by not evaluating the left-hand side of an assignment until the right-hand side has been evaluated - check your manual (and maybe play it safe anyway). Hope this helps. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 3-PK | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."