我正在尝试使C编译器clang进入ANSI C89模式,但没有成功.
这是一个示例会话:
$ cat t.c
#include <stdio.h>
int main(void)
{
puts(__FUNCTION__);
return 0;
}
$ gcc -pedantic -std=c89 -Wall t.c
t.c: In function ‘main’:
t.c:5:7: warning: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic]
puts(__FUNCTION__);
^~~~~~~~~~~~
$ clang -pedantic -std=c89 -Wall t.c
$ clang --version
clang version 3.8.1-24 (tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Run Code Online (Sandbox Code Playgroud)
如您所见,该clang命令完成时没有警告.有没有我在这里缺少的命令选项?
似乎这个特定警告不是由 clang 发出的,但显然确实-std=c89切换了 ANSI C89 语法检查。
例如:
inline int foo(int* restrict p)
{
return *p;
}
Run Code Online (Sandbox Code Playgroud)
将拒绝编译-std=c89 -pedantic -Wall:
tc:1:1:错误:未知类型名称“内联”
tc:1:23: 错误:预期 ')'
int foo(int* 限制 p)
但使用 . 编译时不会出现错误-std=c99。
GCC 5 ( https://gcc.gnu.org/gcc-5/porting_to.html )引入了非标准预定义标识符警告,显然 clang 不适应它。