Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`clang -ansi` extensions

Tags:

c

gcc

clang

c89

I ran into an issue recently where the following toy example compiles cleanly using clang -ansi:

int main(void)
{
    for (int i = 0; 0; );
    return i;
}

but gcc -ansi gives the following error:

a.c: In function ‘main’:
a.c:3:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
a.c:3:5: note: use option -std=c99 or -std=gnu99 to compile your code

Compiling with clang -ansi -pedantic shows that a C99 extension is being used.

a.c:3:10: warning: variable declaration in for loop is a C99-specific feature [-pedantic,-Wc99-extensions]
    for (int i = 0; 0; );
         ^
1 warning generated.

What other extensions does clang allow with the -ansi option? How can I disable them?

like image 866
cyang Avatar asked Oct 06 '22 19:10

cyang


1 Answers

If you are trying to disable extensions in -ansi mode, then you want these warnings treated as errors: use -pedantic-errors instead of -pedantic, or -Werror (or both). For more fine-grained control over errors, see the Clang manual.

like image 181
Brett Hale Avatar answered Oct 10 '22 03:10

Brett Hale