Re:Basics Of Function Pointers In C
by spc476 on Thursday August 01, 2013 @01:22AM
(#6138831)
They can't be any worse than abusing the C preprocessor to implement templates for C code (a sin I committed in college).
[ Parent
| on HN ]
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.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.