| ▲ | kccqzy 3 hours ago | |
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. | ||
| ▲ | uecker 3 hours ago | parent | next [-] | |
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. | ||
| ▲ | jcranmer 3 hours ago | parent | prev [-] | |
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. | ||