4 ms·
> So if in similar code C++ can take advantage of it while C can't because it has to do an actual function call then the C++ version has advantages and might ve
by exDM69 11y ago
> So if in similar code C++ can take advantage of it while C can't because it has to do an actual function call then the C++ version has advantages and might very well be faster
This is a matter of compilation units, not C vs. C++. If you put qsort() in a header file, and call it with a function pointer in the same compilation unit, it will get inlined and work exactly the same way as std::sort (which is in a header file since it's a template).
You can pretty easily verify this yourself by doing a C++ template and a C function with function pointers (in a header file!), compile and inspect the resulting assembly code.
Link-time optimization may relax the compilation unit requirement, but it's not very widely used yet.