News for hackers. Stuff that matters.
Re:Modern programming languages require generics by jjnoakes on Tuesday May 24, 2022 @11:48AM (#31493625)
Why is this limited to the preprocessor? I imagine the compiler proper could inline the compare function parameter into the qsort implementation body in the typical case, at the qsort() call site. (Assuming qsort's implementation was in a header, as the original comment posited).
Re:Modern programming languages require generics by syockit on Tuesday May 24, 2022 @01:52PM (#31495308)
You're right. I tried it here https://godbolt.org/z/457dYWfq5 and if the generic function is visible to the call site and inlineable, then the compare function can be inlined too. I didn't know this, I had always thought that the semantics of function pointer prevented this from being achievable!