Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing ANSI C89 with clang

Tags:

c

clang

c89

I'm trying to make the C compiler clang go into ANSI C89 mode but without success.

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. Is there a command option that I'm missing here?

like image 603
August Karlstrom Avatar asked Nov 08 '22 13:11

August Karlstrom


1 Answers

It seems as if this specific warning is not emitted by clang, but apparently -std=c89 does toggle ANSI C89 syntax checking.

For example:

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

Will refuse to compile with -std=c89 -pedantic -Wall:

t.c:1:1: error: unknown type name 'inline'

t.c:1:23: error: expected ')'
int foo(int* restrict p)

But will compile without errors using -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.

like image 92
valiano Avatar answered Nov 15 '22 06:11

valiano