Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I'm getting clang warning: no previous prototype for function 'diff'

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 ??

like image 810
canesin Avatar asked Jan 26 '14 20:01

canesin


1 Answers

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.

like image 83
Paul R Avatar answered Oct 22 '22 15:10

Paul R