Question

Simple setup: There are n prototypes for functions and implementations of the functions. There is one big array of function pointers. Each function is listed in this array. Some still cause -Wunused-function when compiling 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 };

This is what the setup looks like (just an example)! One of this foo/bar functions now causes a -Wunused-function warning when compiling with gcc. Others don't. Why?

Was it helpful?

Solution

-Wunused-function

Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.

This warning seems to trigger both when a function is never used and when a function is declared (prototyped) but not defined.

Are you sure you didn't miss implementing any of the functions you declared?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top