Re:Modern programming languages require generics
by throwawaymaths on Tuesday May 24, 2022 @01:07PM
(#31494750)
I think "just as well" elides maintainability... I would not want to have to debug a generic sorter written in c preprocessor.
[ Parent
| on HN ]
Re:Modern programming languages require generics
by flohofwoe on Tuesday May 24, 2022 @01:09PM
(#31494782)
In the case of qsort() at least, there wouldn't be "preprocessor generics" involved, because the comparison is done in a user-provided callback function. But both the comparison function and the qsort implementation must be visible to the compiler (or in case of LTO: the linker) for the "auto-specialization" (via the optimizer) to kick in.
It's a bit brittle of course to depend too much on the optimizer, but the whole idea of "zero cost abstraction" in C++ also puts a lot of trust into the optimizer passes.