Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

barazor

why is gcc throwing these errors?

This topic is 5708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this code:
  
#include <stdio.h>

int main()
{
    for (int i=0;i<10;++i)
        printf("blah %d\n",i);

return 0;
}
  
is giving me these errors: bash-2.05a$ gcc test.c -o test test.c: In function `main'': test.c:5: parse error before `int'' test.c:5: `i'' undeclared (first use in this function) test.c:5: (Each undeclared identifier is reported only once test.c:5: for each function it appears in.) test.c:5: parse error before `)'' bash-2.05a$ pico test.c i''m quite baffled, since this is pretty much basic code that has never given me any problems before, but since i reinstalled linux, gcc has been saying that i havent been declaring my variables anybody have any idea why GCC keeps doing this? i''m running version 2.95.3

Share this post


Link to post
Share on other sites
Advertisement
You need to name your file test.cc for c++ features to work. for (int i=0; ...) is the c++ way of doing things. The c way would be:

int i;
for (i=0; ...)


Edit: there are different ways of telling the compiler it's a c++ file of course, that's just the one I use. g++ should give you no hassles when you compile that code as well.

[edited by - premandrake on December 3, 2002 10:26:09 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!