* C99 doesn't allow local scope variables?
@ 2004-01-27 2:30 tabris
2004-01-27 8:05 ` wwp
2004-01-27 11:45 ` Glynn Clements
0 siblings, 2 replies; 3+ messages in thread
From: tabris @ 2004-01-27 2:30 UTC (permalink / raw)
To: linux-c-programming
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
simple C program
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
for (int i=0; i < 2; i++)
printf("crap\n");
};
[tabris@tabriel tmp]$ gcc test.c -o test
test.c: In function `main':
test.c:6: error: `for' loop initial declaration used outside C99 mode
What does that mean, and why am I not allowed to make a local scope variable
for a for{;;} loop?
works fine if i declare the variable outside the loop. But I swear I used to
do this with gcc 2.95.
- --
tabris
- -
Body by Nautilus, Brain by Mattel.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAFc1J1U5ZaPMbKQcRAiJyAJ4namXjJa9zd6Y/VGbR+Y5pyHVjUwCcCy4s
dW251Zxh2o3I97eabiisOMg=
=21yl
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: C99 doesn't allow local scope variables?
2004-01-27 2:30 C99 doesn't allow local scope variables? tabris
@ 2004-01-27 8:05 ` wwp
2004-01-27 11:45 ` Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: wwp @ 2004-01-27 8:05 UTC (permalink / raw)
To: linux-c-programming
Hello tabris,
On Mon, 26 Jan 2004 21:30:30 -0500 tabris <tabris@tabris.net> wrote:
[snip]
> [tabris@tabriel tmp]$ gcc test.c -o test
> test.c: In function `main':
> test.c:6: error: `for' loop initial declaration used outside C99 mode
>
> What does that mean, and why am I not allowed to make a local scope variable
>
> for a for{;;} loop?
>
> works fine if i declare the variable outside the loop. But I swear I used to
>
> do this with gcc 2.95.
ANSI C89 requires int i; to be declared outside from the for(), only ANSI C99
and C++ allow this, IIRC.
Regards,
--
wwp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: C99 doesn't allow local scope variables?
2004-01-27 2:30 C99 doesn't allow local scope variables? tabris
2004-01-27 8:05 ` wwp
@ 2004-01-27 11:45 ` Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2004-01-27 11:45 UTC (permalink / raw)
To: tabris; +Cc: linux-c-programming
tabris wrote:
> simple C program
>
> #include <stdlib.h>
> #include <stdio.h>
>
> int main(void)
> {
> for (int i=0; i < 2; i++)
> printf("crap\n");
> };
>
> [tabris@tabriel tmp]$ gcc test.c -o test
> test.c: In function `main':
> test.c:6: error: `for' loop initial declaration used outside C99 mode
You are trying to use C99 syntax in a file which isn't being treated
as such.
The default C dialect is C89 plus GNU extensions (-std=gnu89). The
Info file for gcc 3.0 says that C99 plus GNU extensions (-std=gnu99)
will become the default once the C99 support is complete. Until then,
if you want to use C99, you have to explicitly ask for it with
-std=c99 or -std=gnu99.
See the "C Dialect Options" node in the gcc Info file for more
details.
> What does that mean, and why am I not allowed to make a local scope variable
> for a for{;;} loop?
>
> works fine if i declare the variable outside the loop. But I swear I used to
> do this with gcc 2.95.
You may have been using a modified version of gcc, although I suppose
that it's possible that -std=gnu99 may have been the default for some
versions.
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-01-27 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-27 2:30 C99 doesn't allow local scope variables? tabris
2004-01-27 8:05 ` wwp
2004-01-27 11:45 ` Glynn Clements
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 NNTP newsgroup(s).