Why is gcc going to default to "GNU dialect of ISO C99?"

Alexey Salmin alexey.salmin@gmail.com
Thu Feb 11 13:48:00 GMT 2010


On Thu, Feb 11, 2010 at 6:23 PM, John (Eljay) Love-Jensen
<eljay@adobe.com> wrote:
> Hi Alexey,
>
>> It all reminds me a story when I won a bottle of beer from my
>> scientific adviser back in 2005. We had a bet: will gcc compile this
>> code:
>> #include <stdio.h>
>>  int main() {
>>   printf("a");
>>   int a;
>>   printf("b");
>>   return 0;
>> }
>> He was so sure that gcc won't allow it that didn't ever tried :) Thus,
>> I think gnu extensions by default are not so bad :)
>
> Why wouldn't GCC compile that code?
>
> It is ISO 9899:1999 compliant.  Even compiles with the -pedantic flag.  (Or
> am I missing something?)
>
> Mmmmmm, beer.  :-)
>
> Sincerely,
> --Eljay
>

It's not ANSI C compliant. And since GNU89 is default for C code it's
reasonable (in some way) for this not to work.
Fortunately I wasn't very familiar with different standarts and stuff
that time, I just knew that it works with GCC :)

This code actually gives a warning with -pedantic and error (your C.O.
:P ) with -pedantic-errors.

salmin@salmin:~/test$ gcc -o test test.c
salmin@salmin:~/test$ gcc -std=gnu89 -o test test.c
salmin@salmin:~/test$ gcc -std=c89 -o test test.c
salmin@salmin:~/test$ gcc -pedantic -o test test.c
test.c: In function ‘main’:
test.c:5: warning: ISO C90 forbids mixed declarations and code

salmin@salmin:~/test$ gcc -pedantic-errors -o test test.c
test.c: In function ‘main’:
test.c:5: error: ISO C90 forbids mixed declarations and code

salmin@salmin:~/test$ gcc -std=c89 -pedantic-errors -o test test.c
test.c: In function ‘main’:
test.c:5: error: ISO C90 forbids mixed declarations and code

salmin@salmin:~/test$ gcc -std=gnu89 -pedantic-errors -o test test.c
test.c: In function ‘main’:
test.c:5: error: ISO C90 forbids mixed declarations and code

salmin@salmin:~/test$ gcc -std=c99 -pedantic-errors -o test test.c

salmin@salmin:~/test$ gcc -std=gnu99 -pedantic-errors -o test test.c

salmin@salmin:~/test$ cat test.c
#include <stdio.h>

int main() {
        printf("a");
        int a;
        printf("b");
        return 0;
}

Alexey



More information about the Gcc-help mailing list