2 ms·
In C you would normally do this with functions that accepted function pointers, not a #define.
by whatshisface 6y ago
In C you would normally do this with functions that accepted function pointers, not a #define.
- vitus 6y agoSort of. You'd be able to define double fprime(double (*f)(double), double x); but you wouldn't be able to define double (*deriv(double (*f)(double)))(double); as C does not support closures. Meanwhile, in C++ you might use std::function<double(double)> deriv(std::function<double(double)> f);
- simias 6y agoI wanted to stick to the original as close as possible, I agree that my code isn't very idiomatic (or even generally a good idea).