public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* function calls before variable declarations does not give error in gcc?
@ 2004-08-31  3:58 Oza Dhairesh
  2004-08-31  5:22 ` Eljay Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Oza Dhairesh @ 2004-08-31  3:58 UTC (permalink / raw)
  To: gcc-help

Hi,

The following code does not give an error wth gcc

void fun(int a){ printf("there u go %d\n",a);}

int main()
{
        char abc[10] = "the";
        int a1 = 10;
        fun(10);
        int a = 1;
} 

gcc --version gave the following o/p:

gcc (GCC) 3.3.1 (SuSE Linux)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

while wth a compiler that gave the following o/p wth gcc --version
2.96

I got the following error:
test1.c: In function `main':
test1.c:10: parse error before `int'

why this difference?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function calls before variable declarations does not give  error in gcc?
  2004-08-31  3:58 function calls before variable declarations does not give error in gcc? Oza Dhairesh
@ 2004-08-31  5:22 ` Eljay Love-Jensen
  2004-08-31  6:31   ` Oza Dhairesh
  0 siblings, 1 reply; 4+ messages in thread
From: Eljay Love-Jensen @ 2004-08-31  5:22 UTC (permalink / raw)
  To: Oza Dhairesh, gcc-help

Hi Oza,

I believe that's actually not an error, according to C99.

GCC 2.96 (a misnomer for a maverick non-GCC release, since there wasn't a 
GCC 2.96, GCC went from 2.95 to 3.0) is probably following C89 standards.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: function calls before variable declarations does not give error in gcc?
  2004-08-31  5:22 ` Eljay Love-Jensen
@ 2004-08-31  6:31   ` Oza Dhairesh
  2004-08-31 12:18     ` Eljay Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Oza Dhairesh @ 2004-08-31  6:31 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

Hi

   Thanks Eljay.

   But even gcc -std=c89 dosnt give an error!! 

BR
Oza

On Mon, 30 Aug 2004 22:58:44 -0500, Eljay Love-Jensen <eljay@adobe.com> wrote:
> Hi Oza,
> 
> I believe that's actually not an error, according to C99.
> 
> GCC 2.96 (a misnomer for a maverick non-GCC release, since there wasn't a
> GCC 2.96, GCC went from 2.95 to 3.0) is probably following C89 standards.
> 
> HTH,
> --Eljay
> 
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: function calls before variable declarations does not  give error in gcc?
  2004-08-31  6:31   ` Oza Dhairesh
@ 2004-08-31 12:18     ` Eljay Love-Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2004-08-31 12:18 UTC (permalink / raw)
  To: Oza Dhairesh; +Cc: gcc-help

Hi Oza,

You're running into a GNU extension to C89, and a standard part of C99.

$ gcc -pedantic -std=c99 -W -Wall -Wno-unused-variable c99.c

No error messages.

$ gcc -pedantic -std=c89 -W -Wall -Wno-unused-variable c99.c
c99.c: In function `main':
c99.c:11: warning: ISO C89 forbids mixed declarations and code

Error messages.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-31 12:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31  3:58 function calls before variable declarations does not give error in gcc? Oza Dhairesh
2004-08-31  5:22 ` Eljay Love-Jensen
2004-08-31  6:31   ` Oza Dhairesh
2004-08-31 12:18     ` Eljay Love-Jensen

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).