This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Why is gcc going to default to "GNU dialect of ISO C99?"
- From: Alexey Salmin <alexey dot salmin at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Cc: "John (Eljay) Love-Jensen" <eljay at adobe dot com>, dclarke at blastwave dot org, aph at redhat dot com, david dot kirkby at onetel dot net, ams at gnu dot org
- Date: Thu, 11 Feb 2010 19:44:19 +0600
- Subject: Re: Why is gcc going to default to "GNU dialect of ISO C99?"
- References: <87a8dc11002110143u533f4451xc9fd0eb88ae3fca5@mail.gmail.com> <C79952E6.1947E%eljay@adobe.com>
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