简体   繁体   English

用clang强制执行A​​NSI C89

[英]Enforcing ANSI C89 with clang

I'm trying to make the C compiler clang go into ANSI C89 mode but without success. 我试图让C编译器clang进入ANSI C89模式,但没有成功。

Here is an example session: 这是一个示例会话:

$ 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

As you can see, the clang command completes with no warning. 如您所见, clang命令完成时没有警告。 Is there a command option that I'm missing here? 有没有我在这里缺少的命令选项?

It seems as if this specific warning is not emitted by clang, but apparently -std=c89 does toggle ANSI C89 syntax checking. 好像这个特定警告不是由clang发出的,但显然-std=c89会切换ANSI C89语法检查。

For example: 例如:

inline int foo(int* restrict p)
{
    return *p;
}

Will refuse to compile with -std=c89 -pedantic -Wall : 将拒绝使用-std=c89 -pedantic -Wall进行编译:

tc:1:1: error: unknown type name 'inline' tc:1:1:错误:未知类型名称'内联'

tc:1:23: error: expected ')' tc:1:23:错误:预期')'
int foo(int* restrict p) int foo(int * restrict p)

But will compile without errors using -std=c99 . 但是使用-std=c99将编译没有错误。

The non-standard predefined identifiers warning was introduced with GCC 5 ( https://gcc.gnu.org/gcc-5/porting_to.html ), and apparently clang did not adapt with it. GCC 5( https://gcc.gnu.org/gcc-5/porting_to.html )引入了非标准的预定义标识符警告,显然clang没有适应它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM