* Static chains and pointers to functions
@ 2003-02-20 20:17 John Lu
2003-02-21 2:01 ` Fergus Henderson
0 siblings, 1 reply; 4+ messages in thread
From: John Lu @ 2003-02-20 20:17 UTC (permalink / raw)
To: gcc
Hi,
I can't think of a good way to implement a call through a pointer
to a nested function, so I was wondering how gcc does it. If the
pointer can point to functions at different nesting levels, how is the
static chain correctly maintained? The only way I can think of doing
it is to use code that dynamically determines the appropriate nesting
level for the function pointer. Is this what gcc does?
Thanks,
John Lu
P.S. The following code illustrates this situation.
void foo(int d) {
void depth1(int c) {
int a=1;
void modify1() {
a=1000;
}
void depth2() {
int a=2;
void modify2() {
a=1000;
}
void end() {
void (*f)();
if (c==1) {
f=modify1;
} else if (c==2) {
f=modify2;
}
f(); /* How is this implemented? */
}
end();
printf("depth2 %d\n",a);
}
depth2();
printf("depth1 %d\n",a);
}
depth1(d);
}
main() {
foo(1);
foo(2);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static chains and pointers to functions
2003-02-20 20:17 Static chains and pointers to functions John Lu
@ 2003-02-21 2:01 ` Fergus Henderson
2003-02-21 2:37 ` Michael Matz
0 siblings, 1 reply; 4+ messages in thread
From: Fergus Henderson @ 2003-02-21 2:01 UTC (permalink / raw)
To: John Lu; +Cc: gcc
On 20-Feb-2003, John Lu <jlu@lsil.com> wrote:
> I can't think of a good way to implement a call through a pointer
> to a nested function, so I was wondering how gcc does it.
<http://gcc.gnu.org/readings.html> will point you to
<http://people.debian.org/~karlheg/Usenix88-lexic.pdf>.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static chains and pointers to functions
2003-02-21 2:01 ` Fergus Henderson
@ 2003-02-21 2:37 ` Michael Matz
2003-02-21 2:45 ` Janis Johnson
0 siblings, 1 reply; 4+ messages in thread
From: Michael Matz @ 2003-02-21 2:37 UTC (permalink / raw)
To: Fergus Henderson; +Cc: John Lu, gcc
Hi,
On Fri, 21 Feb 2003, Fergus Henderson wrote:
> <http://gcc.gnu.org/readings.html> will point you to
> <http://people.debian.org/~karlheg/Usenix88-lexic.pdf>.
Which resides now on
<http://people.debian.org/~aaronl/Usenix88-lexic.pdf> , as the first one
doesn't work anymore.
Ciao,
Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static chains and pointers to functions
2003-02-21 2:37 ` Michael Matz
@ 2003-02-21 2:45 ` Janis Johnson
0 siblings, 0 replies; 4+ messages in thread
From: Janis Johnson @ 2003-02-21 2:45 UTC (permalink / raw)
To: Michael Matz; +Cc: Fergus Henderson, John Lu, gcc
On Fri, Feb 21, 2003 at 02:44:59AM +0100, Michael Matz wrote:
> Hi,
>
> On Fri, 21 Feb 2003, Fergus Henderson wrote:
>
> > <http://gcc.gnu.org/readings.html> will point you to
> > <http://people.debian.org/~karlheg/Usenix88-lexic.pdf>.
>
> Which resides now on
> <http://people.debian.org/~aaronl/Usenix88-lexic.pdf> , as the first one
> doesn't work anymore.
The link is now fixed in readings.html.
Janis
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-02-21 2:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20 20:17 Static chains and pointers to functions John Lu
2003-02-21 2:01 ` Fergus Henderson
2003-02-21 2:37 ` Michael Matz
2003-02-21 2:45 ` Janis Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).