Path: utzoo!mnetor!uunet!husc6!uwvax!dogie!uwmcsd1!ig!jade!ucbvax!decvax!decwrl!pyramid!prls!gardner From: gardner@prls.UUCP (Robert Gardner) Newsgroups: comp.sys.mac Subject: Re: LSC, function pointers, and segments Message-ID: <8250@prls.UUCP> Date: 11 Jan 88 22:55:13 GMT References: <782@daisy.UUCP> <22358@ucbvax.BERKELEY.EDU> <8217@prls.UUCP> <22519@ucbvax.BERKELEY.EDU> Reply-To: gardner@prls.UUCP (Robert Gardner) Organization: Philips Research Labs, Sunnyvale, California Lines: 41 In article <22519@ucbvax.BERKELEY.EDU> oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) writes: >In article <8217@prls.UUCP> gardner@prls.UUCP (Robert Gardner) writes: >>I started working on segmenting a large program that uses function pointers >>rather extensively and got worried about assigning a function pointer >>in one segment, unloading that segment, and having it accessed later from >>another segment. Is the function pointer still valid? >Yes. What is actually being passed around is the reference to the function >in the jump table, just as you surmised. The reason this works for static >function is, they go in the jump table too Thank you. A friend answered this question for me after I posted but added an interesting observation that perhaps ought to be mentioned. And if this is wrong, the THINK representative should please clarify! When referencing the address of static functions, they are added to the jump table and the jump table address is used only if they are assigned to global variables or passed as function parameters to a non-static function. Otherwise the PC-relative address is used. This was discovered because the friend was passing a static function to a function which had access to a previously-stored address of a static function in a static variable. He would then compare the saved address with the passed address for equality. Turned out they would never compare equal because one was a PC-relative address and one was a jump table entry! Changing the variable that he stored the address in from static to global solved the problem. This technique used by LSC (if we understand it correctly) is actually quite intelligent -- but this experience shows that there are pitfalls to being intelligent, especially when your intelligence is undocumented! I like what they've done, but it should be mentioned somewhere... >P.S.: You posted to: >Newsgroups: comp.sys.ibm.pc,comp.sys.mac,comp.sys.atari.st I realized that too late and sent apologies to those newsgroups (thus wasteing even more net bandwidth :-). I haven't figured out how to post a message on a new subject without doing a follow-up to an old one, and I forgot to check the Newsgroups line... Robert Gardner