Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc warning: function used but not defined

Tags:

I am getting the warning: function used but not defined. I have static __inline__ in header file say a.h. The header file is included in a.c. I would like put all those inline function which are in header files into the .c files. Following code gives the idea of my problem.

Orginal code:

a.h:

static __inline__ function1(){     function definition;   } 

I changed:
a.h:

static function1(); 

a.c:

#include "a.h"  static function1(){    function definition; } 

On doing above I got the warning:

   warning: function function1 is used but not defined.  

Could you please let me know why i am getting such warning? I would like to transfer all the __inline__ function into the .c so that I won't get the warning:

  warning: function1 is could not be inlined, code size may grow. 

Thanks in advance

like image 798
thetna Avatar asked Apr 02 '11 22:04

thetna


1 Answers

You've declared the function to be static. This means that it is only visible within the current compilation unit. In other words: the implementation is only visible inside the a.c file. You need to remove the static keyword both in the a.h and a.c so that other .c files can see the function. You should specify a return value, e.g. void function1(); because it implicitly is int if you didn't specify one.

like image 140
DarkDust Avatar answered Sep 18 '22 01:09

DarkDust