I have the following declaration in my code:
//Central diff function, makes two function calls, O(h^2)
REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL))
{
// diff = f(x + h) - f(x -h)/2h + O(h^2)
return ((*func)(x + h) - (*func)(x - h))/(2.0*h + REALSMALL);
}
This goes in a "utils.h" file. When I compile a test using it it gives me:
clang++ -Weverything tests/utils.cpp -o tests/utils.o
In file included from tests/utils.cpp:4:
tests/../utils/utils.h:31:6: warning: no previous prototype for function 'diff' [-Wmissing-prototypes]
REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL))
What I`m missing here ??
Since you defined (not declared) your function in a header then you should make it inline. Change:
REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL))
to:
inline REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL))
Or just move the definition into a .c file and keep just a prototype in the header file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With