Using GCC's nested functions with wide pointers and no trampolines
The article discusses the use of nested functions in GCC with wide pointers and without trampolines. It highlights the advantages of nested functions for accessing local state and the challenges posed by traditional trampoline implementations. The author proposes alternative solutions using wide pointers and function descriptors to improve efficiency and security.
- ▪Nested functions are useful for writing kernels that can access local state without needing to pass it as a void pointer.
- ▪GCC supports nested functions as an extension but traditionally uses trampolines, which can lead to security issues.
- ▪The article suggests using wide pointers or function descriptors as alternatives to improve performance and avoid memory leaks.
Opening excerpt (first ~120 words) tap to expand
hljs.initHighlightingOnLoad(); Using GCC's Nested Functions with Wide Pointers and no Trampolines Martin Uecker, 2026-01-06 Introduction Nested functions are extremely useful, which is why basically any computer language since ALGOL60 has them. Except C. In particular, nested functions are useful to write kernels for passing them to higher-order functions. The kernels can access local state, and this is important because it then does not have to be passed as a void pointer to the higher-order function. void tree_increase_all(tree(int) *t, int increment) { void update(int *value) { (*value) += increment; } tree_walk(t, update); } For very simply nested functions it makes also sense to use a lambda expression, i.e. an anonymous nested function.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at Codeberg.