Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Unsafe use of an object field as a var or > 4 byte parameter Message-ID: <16369@hoptoad.uucp> Date: 22 Mar 91 19:13:16 GMT References: <4749@syma.sussex.ac.uk> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Electronics for Imaging, San Bruno CA Lines: 31 In article <4749@syma.sussex.ac.uk> paulr@syma.sussex.ac.uk (Paul Russell) writes: >When passing a parameter such as a Str255 as a parameter >to a method, where the parameter is also an object field, >the MPW Pascal compiler complains: > >### Pascal - Error 815 Unsafe use of an object field as a var or > 4 byte parameter > >I can understand why it might object to a VAR parameter being >passed in this way, since that would in effect be dereferencing >a handle. But why should it object when the parameter is not >VAR ? For non-VAR parameters surely a local copy of the parameter >is made before the called function has a chance to move memory ? Nope. A pointer is passed. It's the responsibility of the called routine, not the caller, to copy it. This is likely the first thing the called routine does. So why is it unsafe? The routine may be in another segment, so the routine call will turn into a LoadSeg instruction, which may move memory. >(BTW - THINK Pascal doesn't care about this - does that mean that >it handles the problem for you, or that it just ignores it ? ;-)) It just ignores the problem. But you can still get bitten. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com FROM THE FOOL FILE: "Yet another piece of evidence that it's a Communist society which is being presented as good, but which we probably would not want to live in." -- Ken Arromdee on rec.arts.startrek, on the Federation's Red Menace