What causes compiler to warn for unused functions?

2020-06-29 09:56发布

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?

1条回答
一夜七次
2楼-- · 2020-06-29 10:29

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

查看更多
登录 后发表回答