【问题标题】:Enforcing ANSI C89 with clang使用 clang 强制执行 ANSI C89
【发布时间】:2017-11-29 18:15:58
【问题描述】:

我正在尝试让 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

如您所见,clang 命令在没有任何警告的情况下完成。我在这里缺少一个命令选项吗?

【问题讨论】:

  • 应该已经成功了,我想你可能在clang中发现了一个bug。

标签: c clang c89


【解决方案1】:

似乎这个特定的警告不是由 clang 发出的,但显然-std=c89 确实切换了 ANSI C89 语法检查。

例如:

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

将拒绝用-std=c89 -pedantic -Wall编译:

t.c:1:1: 错误:未知类型名称“内联”

t.c:1:23: 错误:预期为 ')'
int foo(int* 限制 p)

但使用 -std=c99 编译不会出错。

GCC 5 (https://gcc.gnu.org/gcc-5/porting_to.html) 引入了非标准预定义标识符警告,显然 clang 没有适应它。

【讨论】:

  • Clang 也不会在 "%lf" 中为 printf 系列函数捕获无效长度修饰符 l。在 C99 中有效。
猜你喜欢
  • 2012-08-09
  • 1970-01-01
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-02
  • 2011-09-12
  • 1970-01-01
相关资源
最近更新 更多