3 ms·
Sometimes it is a useful sin, many data structure libraries for C use this for: 1) genericity 2) (extreme) speed It's (unfortunately) impossible for C to equa
by aktau 13y ago
Sometimes it is a useful sin, many data structure libraries for C use this for:
1) genericity
2) (extreme) speed
It's (unfortunately) impossible for C to equal C++ templates in this: write once, use for multiple datatypes (without macros).
For people who like copy pasting, generic macros is on the horizon for C11, which is rapidly being implemented (and mostly works) for Clang and GCC, the most important compilers. Read more about it here: http://www.robertgamble.net/2012/01/c11-generic-selections.html http://www.robertgamble.net/2012/01/c11-generic-selections.h...
Simply put, it allows to create a small "shim"-macro that detects the type of the input parameters and redirect to an actual function based on type.