|
|
|
|
|
by lederhosen
3360 days ago
|
|
qsort might be general in the element type, but not in the container type. That is, it will only work for arrays.
Also without LTO it will be very expensive as it cannot inline the compare function call. C++ sort is just faster and more powerful. |
|
That is a clear advantage of C++.
> Also without LTO it will be very expensive as it cannot inline the compare function call.
Templates force you to expose the implementation in a header file. In C you can choose. If you move the qsort implementation in a header file, the compiler should not have any trouble inlining it.
Inlining is not always a win, though (slower compiles, bigger code, more cache misses).