home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1763 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  1.8 KB

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