Using GCC's Nested Functions with Wide Pointers and No Trampolines II
- Programming
- Compilers
- Developer Tools
- Open Source
The post is about GCC nested functions, which let a function defined inside another function read the parent’s local variables. Traditional GCC implements captured nested functions by building a tiny helper stub called a trampoline that sets up the hidden environment pointer and then jumps into the real code. That works, but it usually means executable stack memory and it blocks some compiler optimizations. The new approach packages the code pointer together with its environment as a wider function reference instead of pretending every callback is a plain C function pointer.
If you own a C API, keep passing an explicit context pointer because it stays portable and predictable. If GCC or future C standards adopt closure-like function references, the payoff is less boilerplate and better type safety around callbacks, not just a security fix.
-
uecker.codeberg.page
- Discuss on HN