News for hackers. Stuff that matters.
Re:Modern programming languages require generics by brabel on Tuesday May 24, 2022 @11:14AM (#31493173)
Does the necessary pointer casting in the implementations also make it slower than it should be (the specialized versions generated by compilers that support generics wouldn't have any casting)?
Re:Modern programming languages require generics by eptcyka on Tuesday May 24, 2022 @11:23AM (#31493305)
Its not the pointer casting, its the indirect function call that probably can be cached but it will always be another memory location that the CPU will need to jump to.
Re:Modern programming languages require generics by jjnoakes on Tuesday May 24, 2022 @11:48AM (#31493631)
If the compare function is inlined into the qsort() body, there wouldn't need to be any function call. I think that was the point of the question above.
Re:Modern programming languages require generics by OnACoffeeBreak on Tuesday May 24, 2022 @12:03PM (#31493812)
The way to answer this question is to look at the assembly code generated by the compiler with various optimization levels and see whether the compiler ever inlines the compare function.

https://godbolt.org/ might be useful for this exercise.

Re:Modern programming languages require generics by jjnoakes on Tuesday May 24, 2022 @12:36PM (#31494285)
Did you reply to the right comment?