public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexey Salmin <alexey.salmin@gmail.com>
To: gcc-help@gcc.gnu.org
Cc: "John (Eljay) Love-Jensen" <eljay@adobe.com>,
	dclarke@blastwave.org, aph@redhat.com,  	david.kirkby@onetel.net,
	ams@gnu.org
Subject: Re: Why is gcc going to default to "GNU dialect of ISO C99?"
Date: Thu, 11 Feb 2010 13:48:00 -0000	[thread overview]
Message-ID: <87a8dc11002110544q2531b46x8344c74f70b1b556@mail.gmail.com> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2010-02-11 13:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11  2:40 Dennis Clarke
2010-02-11  9:43 ` Alfred M. Szmidt
2010-02-11 12:00   ` Alexey Salmin
     [not found]     ` <C79952E6.1947E%eljay@adobe.com>
2010-02-11 13:48       ` Alexey Salmin [this message]
     [not found]         ` <C79973C1.194A3%eljay@adobe.com>
2010-02-11 14:58           ` Alexey Salmin
2010-02-11 15:11             ` John (Eljay) Love-Jensen
2010-02-12  5:32     ` Patrick Horgan
  -- strict thread matches above, loose matches on Subject: below --
2010-02-11 17:14 Dennis Clarke
2010-02-11 14:50 Dennis Clarke
2010-02-11 14:14 Dennis Clarke
2010-02-11 14:42 ` Alexey Salmin
2010-02-11 13:44 Dennis Clarke
2010-02-11 14:00 ` Alexey Salmin
2010-02-10 17:00 Dr. David Kirkby
2010-02-10 17:26 ` Andrew Haley
2010-02-10 17:45   ` Dr. David Kirkby
2010-02-10 18:07     ` Alfred M. Szmidt
2010-02-10 19:25       ` Dr. David Kirkby
2010-02-10 20:59         ` Kevin P. Fleming
2010-02-10 18:39     ` Andrew Haley
2010-02-11  2:46     ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a8dc11002110544q2531b46x8344c74f70b1b556@mail.gmail.com \
    --to=alexey.salmin@gmail.com \
    --cc=ams@gnu.org \
    --cc=aph@redhat.com \
    --cc=david.kirkby@onetel.net \
    --cc=dclarke@blastwave.org \
    --cc=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).