2 ms·
> They're not even a C thing per se Really? from stdlib.h: void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const
by viraptor 16y ago
> They're not even a C thing per se
Really? from stdlib.h:
void
qsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *));
- yason 16y agoNot even a C thing per se, as in "C has function pointers but it's not really a C specific feature as some other languages have them too. Like assembly, very obviously." Many other languages don't. If they're sufficiently high-level they might have function objects or closures, which often cover everything you want. If they're Java they have neither but you can write a Visitor-style class or some other scheme from the design patterns book that emulates the behaviour of a function pointer. But fundamentally (and when the program is compiled down to machine code also hopefully) they're just function pointers.
- eru 16y agoI agree. Though what it gets compiled down to depends on the compilation strategy. If your compiler is smart enough, and your use of functions as variables / function pointers is weak [1] enough, your functions may, say, just get inlined into a big case-statement-like construct. [1] In the sense of http://en.wikipedia.org/wiki/Strength_reduction http://en.wikipedia.org/wiki/Strength_reduction