#include <stdio.h>
int main()
{
for (int i=0;i<10;++i)
printf("blah %d\n",i);
return 0;
}
why is gcc throwing these errors?
this code:
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
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:
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement