home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.std.c++
- Subject: Re: Zero-length structures and pointer comparisons
- Message-ID: <24398@alice.att.com>
- Date: 12 Dec 92 19:56:40 GMT
- Article-I.D.: alice.24398
- References: <9234601.10277@mulga.cs.mu.OZ.AU> <1992Dec11.231131.10956@microsoft.com> <24392@alice.att.com> <1992Dec12.162211.5076@ucc.su.OZ.AU>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Murray Hill NJ
- Lines: 38
-
- In article <1992Dec12.162211.5076@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
-
- > >It shouldn't need to do that. At most one trampoline is ever necessary
- > >for a given nested function during its lifetime, namely the one that
- > >binds the lexically surrounding context that was current when the
- > >block containing the definition of that function was entered.
-
- > Are you saying that if I have a recursive function with a nested
- > function in it, and store the address of the nested function in scope
- > at the time of entering the n'th recursion into an array in slot n,
- > then executing the j'th slot will access the n'th activation record
- > and not the j'th one? (I.e. all the functions in the array
- > access the most recent activation record?)
-
- No, that's just the opposite of that I said.
-
- I said `the context that WAS current.'
-
- Perhaps an example will make it clearer:
-
- void (*p)(void);
- void f(int n)
- {
- void g() { printf("%d\n", n); }
- if (n == 3)
- p = &g;
- if (n == 5)
- (*p)();
- else f(n+1);
- }
-
- I am claiming that calling f(0) should print 3, not 5, because the
- address stored in p should correspond to the stack frame in which
- n is 3. Indeed, that is just what gcc does. It is also what every
- other language I know does that supports such functions at all.
- --
- --Andrew Koenig
- ark@europa.att.com
-