4 ms·
Function pointers are not the problem. Returning function pointers is the problem. And the problem is that we don't know if the caller will run that code or no
by gavinhoward 2y ago
Function pointers are not the problem. Returning function pointers is the problem.
And the problem is that we don't know if the caller will run that code or not, but if they do, that code is not in the subprogram anymore.
You can pass function pointers to callees, no problem.
- two_handfuls 2y agoOk, the problem is we don’t know whether that code will be called. So if we added some way to require that value to be used, something similar to `std::hint::must_use`, then we may be able to return function pointers?
- gavinhoward 2y agoNo, because we also don't know what the program does if it is called because it is Turing-complete.
- two_handfuls 2y agoI’m confused. That also holds for functions that don’t return a function pointer, so this cannot be a good argument for banning returning function pointers.
- gavinhoward 2y agoBy program, I mean the function pointer. The caller is not part of the subprogram, but the returned function pointer is, and if the caller runs it, it leaks out, in the same way async and other things do.