News for hackers. Stuff that matters.
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.
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.

Re:Modern programming languages require generics by randbox on Tuesday May 24, 2022 @02:21PM (#31495689)
The only preprocessor code required for writing 'static inline' header functions is "#pragma once". Inline functions look like normal functions.