If the nested function does not depend on its "parent" stack at all, then this is just a simple function - the attachment is syntactic (and sliding) sugar.
And if you donβt take the address of the nested function, then the code is not needed. So you need something more to get it all involved.
Here is an example of a dummy example:
// file tc int doit(int (*fun)(int), int x) { return fun(x); } int foo(int a) { int add(int b) { return a + b; } return doit(&add, 2); } int main(void) { return foo(1); }
$ gcc tc tc: In function 'foo': tc:8:13: warning: trampoline generated for nested function 'add' $ ./a.out $ echo $? 3 $ execstack a.out X a.out
source share