Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!mailrus!ames!haven!umd5!zben From: zben@umd5.umd.edu (Ben Cranston) Newsgroups: comp.sys.mac.programmer Subject: Re: Passing pointers to functions (was Re: HLock) Summary: What about exporting local function pointer? Message-ID: <5832@umd5.umd.edu> Date: 28 Dec 89 21:59:57 GMT References: <859@lclark.UUCP> <9389@hoptoad.uucp> Reply-To: zben@umd5.umd.edu (Ben Cranston) Organization: University of Maryland, College Park Lines: 38 In article <859@lclark.UUCP> dan@lclark.UUCP (Dan Revel) writes: > Is it safe to pass pointers to functions > across segment boundaries? (I think this question might be > rephrased: 'are my code segments going to be relocated while > my program is running?', is that right?) In article <9389@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) replies: > Your code segments may be relocated if you do UnloadSeg on them, > as many people recommend. However, MPW at least will generate > function pointers into the jump table rather than to the function > itself in the case of cross-segment references. Within a single > segment, it will produce pointers to the functions. I would > hope that THINK C does the same. > This means that if you take a function pointer while you're in a > different segment from the function, what you actually get is the > jump table entry for the functions, so even if the segment is > relocated, your pointer will still be valid. The other case is also worth considering. Suppose you take a pointer to a local function (so the pointer generated is to the real function, not to a jump table entry). You then pass this pointer to a function in another segment. It then uses the pointer, and does not get the benefit of going through a jump table entry. In order for this to fail, though, the original segment must have been unloaded. While this could happen in the case of an initialization segment that will never be returned to, in the usual case of heirarchical segment organization the upper level segment cannot be unloaded for fear of invalidating return addresses and other pointers that might be saved in the stack frame for the calling routine in that segment. -- Sig DS.L ('ZBen') ; Ben Cranston * Network Infrastructures Group, Computer Science Center * University of Maryland at College Park * of Ulm