在我们平时写c代码的时候,经常不注意会使编译中显示warning,warning有时我们不注意会导致很多的隐形问题,导致有时很难定位问题的所在,如果能够将warning及早的辨识出来,对代码的规范性以及一些隐形的问题的可控性是有所改善的。
#include <stdio.h>
int main()
{
int a;
return 0;
}
上面的代码(假设为test.c)使用gcc编译打印如下:
只显示警告:
root@admin:# gcc -o test -Wall test.c
test.c: In function ‘main’:
test.c:6:6: warning: unused variable ‘a’ [-Wunused-variable]
int a;
^
root@admin:#
将警告编译时显示为错误:
root@admin:# gcc -o test -Wall -Werror test.c
test.c: In function ‘main’:
test.c:6:6: error: unused variable ‘a’ [-Werror=unused-variable]
int a;
^
cc1: all warnings being treated as errors
root@admin:#