What makes the compiler warn about unused functions?

Easy setup: there are n function prototypes and function implementations. There is one big array of function pointers. Each function is listed in this array. Some of them still call the -Commute function when compiled with gcc.

code:

void foo1(void);
void foo2(void);
void bar1(void);
void bar2(void);

/* and their implementations */

void (*functions[])(void) = { foo1, foo2, bar1, bar2 };

      

Here's what the setup looks like (just an example)! One of these functions foo / bar now raises a -Wunused-function warning when compiled with gcc. Others don't. Why?

0


source to share


1 answer


-Wunused-function

Warn when a static function is declared but not defined, or an unused static function is not being used. This warning is included -Wall .

This warning seems to be triggered when the function is never used and when the function is declared (prototyped) but not defined.



Are you sure you haven't missed any of the functions you've declared?

+4


source







All Articles