是什么原因导致的编译器警告未使用的功能呢? [英] What causes compiler to warn for unused functions?
问题描述
设置简单:对于功能和功能实现ñ原型。有函数指针的一个大阵。列出了每个函数这个数组中为止。用gcc编译时,有些仍然会造成-Wunused功能。
code:
无效foo1(无效);
无效foo2的(无效);
无效BAR1(无效);
无效BAR2(无效);/ *及其实现* /无效(*函数[])(无效)= {foo1,foo2的,BAR1,BAR2};
这是设置的样子(只是一个例子)!一本富/酒吧功能,现在用gcc编译时会导致-Wunused功能的警告。有的则没有。为什么呢?
-Wunused功能
每当警告静态函数声明,但没有定义或一个非内联static函数未使用。这个警告是由 -Wall 启用。
块引用>此警告似乎触发的两个的当一个函数从未使用过的和的当函数声明(原型),但没有定义。
你确定你没有错过实现任何你声明的功能是什么?
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?
解决方案-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?
这篇关于是什么原因导致的编译器警告未使用的功能呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!