Enforcing ANSI C89 with clang

Question

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?


Show source
| c   | clang   | c89   2017-11-29 19:11 1 Answers

Answers to Enforcing ANSI C89 with clang ( 1 )

  1. 2017-11-29 20:11

    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.

Leave a reply to - Enforcing ANSI C89 with clang

◀ Go back