5 ms·
I committed what I now realize were true crimes against software engineering when I first learned of function pointers.
by adambard 13y ago
I committed what I now realize were true crimes against software engineering when I first learned of function pointers.
- spc476 13y agoThey can't be any worse than abusing the C preprocessor to implement templates for C code (a sin I committed in college).
- aktau 13y agoSometimes 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.
- roel_v 13y agoWhat's wrong with that? It allows you to write type-safe sort-of-generic data structures. It's certainly better than 'generic' data structures that work on void*'s.