logoalt Hacker News

kccqzy • 08/15/2026 • 2 replies • view on HN

C++ solves this problem by simply not allowing a nested function (lambda) to be converted to a function pointer, and thereby avoids this problem of trampolines and executable stack altogether. I think that’s a better design.


Replies

uecker • 08/15/2026

C++ has the same solution as I propose here: A wide function pointer type.

In C++ it is called std::function, but this comes with a bit of baggage. C++ 26 has std::function_ref which would be the exact equivalent to my wide pointer.

https://godbolt.org/z/GaP9jb5rE

jcranmer • 08/15/2026

A C++ lambda that doesn't close over anything can be converted to a function pointer: https://eel.is/c++draft/expr.prim.lambda#closure-12 This feature does turn out to be useful if you need to pun a C++ interface into a function pointer for a C ABI function.

➕ show 1 reply