User forums > Using Code::Blocks

Problem compiling "for loop" with codeblocks compiler.

<< < (2/3) > >>

zabzonk:
> Wrong, C::B supports single file compilation, too.

What is "wrong"? Do you deny that that CB is project based? Can you use Build Options without a project, which is what the OP needs to do, without using what you yourself say is "bad practice"? No, you can't.

Jenna:
I gues you use a *.c file.
The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.

zabzonk:
> The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.

But then he runs into problems if he uses C99 features not supported by C++.

Radek:
IMO, Jens is correct. You problem consists in "for( int count = 1 ; ..." This kind of declaring local variables in a loop statement (or other statements) is usual in C++ for a long time. Perhaps, a norm is it starting from C99. GCC is over strict sometimes ...

(1) Either switch to C++ by renaming 48.c to 48.cpp or selecting C++ compiler explicitely.
(2) Or declare "int count" like a normal variable declaration at the beginning of main().

When you opt for (1) you can get a similar paranoid message. When you opt for (2), you should pass even with a  C compiler.

zabzonk:
@Radek. It is perfectly legal (and good)  C99  code, and the OP obviously wants to use C99. Telling him to switch to C++, a completely different language, is IMHO very bad advice.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version