编译选项的使用

1.禁止隐式声明

-Werror=implicit-function-declaration 编译选项中加了这个,隐式声明不过,报error而不是warning了

eg: test.c
int main(int argc, char *argv[])
{
    char *pstr = "hello nihao";
    printf("l pstr=%s
", pstr);
}

[ubuntu @tmp]$ gcc test.c -o pp
test.c: In function ‘main’:
test.c:5:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
  printf("l pstr=%s
", pstr);


[ubuntu @tmp]$ gcc test.c -Werror=implicit-function-declaration  -o pp
test.c: In function ‘main’:
test.c:5:2: error: implicit declaration of function ‘printf’ [-Werror=implicit-function-declaration]
  printf("l pstr=%s
", pstr);
  ^
test.c:5:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
cc1: some warnings being treated as errors

2. __unused 加载参数后面表示参数不使用,就不会报参数没有使用的警告了

int main(int argc __unused, char *argv[] __unused) 
{
    return 0;      
}
原文地址:https://www.cnblogs.com/hellokitty2/p/9096272.html