Using ANSI C89 with clang

I am trying to get the C clang compiler to go into ANSI C89 mode, but without success.

Here is an example session:

 $ cat tc #include <stdio.h> int main(void) { puts(__FUNCTION__); return 0; } $ gcc -pedantic -std=c89 -Wall tc tc: In function 'main': tc:5:7: warning: ISO C does not support '__FUNCTION__' predefined identifier [-Wpedantic] puts(__FUNCTION__); ^~~~~~~~~~~~ $ clang -pedantic -std=c89 -Wall tc $ 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 completed without warning. Is there a command option that I'm missing here?

+5
source share
1 answer

This special warning doesn't seem to be emitted by clang, but apparently -std=c89 does an ANSI C89 syntax check.

For instance:

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

Refuses to compile with -std=c89 -pedantic -Wall :

tc: 1: 1: error: unknown type name 'inline'

tc: 1: 23: error: expected ')'
int foo (int * limit p)

But it will compile without errors using -std=c99 .

A warning about non-standard predefined identifiers was introduced using GCC 5 ( https://gcc.gnu.org/gcc-5/porting_to.html ) and, apparently, clang did not adapt to it.

0
source

Source: https://habr.com/ru/post/1273749/


All Articles