Function defined but not used warning in C -


I have several source files (both .c and .h files). Header files contain many functions that are partially used in only one source. File.Suppose aH, b.h are header files and are a.c and b.c C files A.h.c.c. But it is only one of those tasks that are in one. H is used and the rest is not used. After compilation I get the following warnings:

  The function is defined XXXX but it has not been used.  

But those XXXX functions which are not used in a.c are b.c. Therefore, I can not completely remove those tasks, so I decided to create a separate file with only those XXXX functions and it was used wherever it was used. By doing so many numbers of header files are being generated. Anyone can suggest some effective way to solve this problem.

"function is defined but it is not used" warning only internal linkage Which is declared as static , these functions are only available in a translation unit, so the compiler always knows if they are Used (in the program) or not if you do not have these functions in their translation unit Rb does not give up, if these things are known to be unused, and generate a warning.

You are saying that these tasks are not used in AC but it is used before. "This is not true. When you type the static in the header file To declare (and define) a function in, then each translation unit includes that header file in its internal copy function. Although these functions look exactly the same, they are still different Fully independent working The fact is that they have the same name and they do not have any compiler in the compiler, therefore, in bc you get a completely free copy of the function, which was used (As you say), but completely free copy has not been used in ac .

In this case there is a question why Why are you doing this on the stable function in the header file on the earth Are you not defining? If you really need to do this (i.e. if you really want to create a separate internal "clone" of this function in each translation unit), you can use some compiler-specific methods Can work around the warning. Like GCC, for example, you can declare the function with the __ attribute __ ((unused)) the warning will not be issued for this function.

But generally there is no need to define the function in a 'header file' normally with external linkage (i.e., a still ) Using a function, it defines it in any .c files and puts the declaration (prototype) in the header file. The compiler will not issue any warning in this case, even if the function has been declared, but it has not been used in some translation unit.


Comments