gcc -c -x c -std=c89 -pedantic-errors -Wall -Wextra -Wno-comment -Wno-parentheses -Wno-format-zero-length test.c
然而,最近我尝试使用Clang编译器,并得到了不同的结果。以下是我的样例测试代码:
int main(void)
{
int length = (int)strlen("Hello");
return 0;
}
使用Clang编译时,我得到了以下错误,而使用GCC编译时,我得到了相同的基本信息,但它将其标记为警告:
test.c:3:22: error: implicitly declaring library function 'strlen'
with type 'unsigned long long (const char *)'
int length = (int)strlen("Hello");
如果我移除-pedantic-errors选项,或者将其更改为-pedantic,Clang只会将其标记为警告,这正是我想要的。然而,根据GCC文档,-pedantic-errors选项会导致被认为是语言扩展的警告被标记为错误,但在C89中不使用函数原型不是一种扩展。因此,我有三个基本问题:
Has Clang changed the meaning of -pedantic-errors from the meaning used by GCC, or am I misinterpreting something?
What is the best set of options that will enforce adherence to the selected standard and will issue errors for all non-conforming code?
If I continue to use -pedantic-errors with Clang is there a way to get it to issue a warning instead of an error in specific cases? In another posting on this site an answer was given that said to use the following, where foo is the error:
-Wno-error=foo
-Wno-error=implicitly declaring library function 'strlen'
with type 'unsigned long long (const char *)'