Taking the address of a nested function in C has historically required an executable stack trampoline. This runtime hack compromises process security, which modern systems prevent with non-executable stack flags. Moving those trampolines to the heap avoids stack execution, but it incurs continuous allocation overhead and risks memory leaks when combined with longjmp.
GCC introduces guarantees that eliminate this problem. When a nested function does not capture variables from its enclosing frame, the compiler completely bypasses trampoline generation even without compiler optimizations enabled. You can safely return such functions or pass them as bare callback pointers without security or performance penalties.
For callbacks that must carry state, wide pointers offer a viable path toward fat function pointers in C. They couple code addresses directly with execution context, providing safe closures without sacrificing security or allocation speed.






