3 ms·
> Compilers are perfectly capable of inlining calls to function pointers. Does this happen even if the function that calls the callable (in this case sort) is
by ot 15y ago
> Compilers are perfectly capable of inlining calls to function pointers.
Does this happen even if the function that calls the callable (in this case sort) is not inlined? This would mean that the compiler generates a specialized function, say sort_{somerandomnumber} with the user-defined callable inlined into, and this seems kind of unlikely to me (while with templates the compiler is forced to do so).
In both your example the body of the caller (array do and for_each) is so small that I assume it is inlined.
- comex 15y agoNo, but you could get the same effect by writing a short wrapper function and getting sort inlined into that. (Might be difficult in some cases, but I could imagine a "qsort_efficient" which is declared __attribute__((always_inline)).)