> Why so? When we do the call the return address gets pushed and we jump
> to the pointer. From then on the (nested) function execution is
> standard.
Not exactly.
> It references locations in its frame on the stack for its
> local variables, and locations higher up the stack for the enclosing
> functions variables.
Not always.
> The nested function isn't visible from anywhere else so
Here is point of mistake. BIG mistake. Yes, nested function itn't visible from
anywaye else. POINTER to that function visible from "anywhere else". And then
if yu have pointer to function you can call it, you know. The question is
"how" ?
> the enclosing functions frame must be above it on the stack
> and the compiler can generate the right relative offsets for them.
"enclosing functions frame" must be above it on the stack. Just not "directly
above" - it can be everywhere in the stack. It can be even "in the stack of
other thread".
> Where does a trampoline come into it?
Just where yuo missed all interesting parts :-)
-- Sample in standard pascal without GNU extension --
procedure for_each(_from,_to:integer;procedure _do(x:integer));
var
i:integer;
begin
for i:=_from to _to do
_do(i);
end;
procedure draw_table;
var
y:integer;
procedure one_step(x:integer);
begin
write(x*y:4);
end;
begin
for y:=1 to 10 do begin
for_each(1,10,one_step);
writeln;
end;
end;
begin
draw_table;
end.
-- cut --
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/