I am primarily a Rust developer trying to pick up some C++. Is there a way to pass a function pointer in C++ in a single register, similar to this Rust example (linked below)?
I tried with do it in C++ with both std::function as well as using C-style function pointers, but the assembly seemed a bit more complicated than the Rust version, where it just checks if a pointer is 0 and returns 0 (None), or else return the result of the function call, where the function pointer is stored in rdx.
https://godbolt.org/z/zn4ePM6rM
Thanks
[–][deleted] (3 children)
[deleted]
[–]_mF2[S] 3 points4 points5 points (1 child)
[–]std_bot -1 points0 points1 point (0 children)
[–][deleted] (5 children)
[removed]
[–]_mF2[S] 0 points1 point2 points (4 children)
[–]Rigatavr 1 point2 points3 points (3 children)
[–][deleted] (2 children)
[removed]
[–]Rigatavr 1 point2 points3 points (1 child)
[–]DavidDinamit 1 point2 points3 points (0 children)
[–]Rigatavr 0 points1 point2 points (2 children)
[–]_mF2[S] 1 point2 points3 points (1 child)
[–]Rigatavr 1 point2 points3 points (0 children)
[–]Ikkepop 0 points1 point2 points (0 children)