Why should I use namespaces and int main in Code blocks while there are no namespaces in turbo c++ and I can use void main without returning any value as I learnt in schools. Is the compiler different, Is the C++ version different?
-
5Turbo c++ is very old and very far from being standard c++. void main() is not standard c++. – drescherjm Jul 05 '14 at 12:16
-
Why are you using turbo c++ in the first place? – shuttle87 Jul 06 '14 at 03:54
2 Answers
First of all, Turbo C++ is a compiler bundled with an IDE targetting MS-Windows. Code Block is an IDE supporting several compilers and platforms. That is the main difference between these two tools, so you are not comparing exactly the same things.
Secondly, int
is the standard return value for main
, which is also standard by convention in C and C++ for program source code entry points (1). C++ compilers operating in standard mode expect programs to be written that way, so your programs should conform these expectations, if you want to use conforming C++ compilers, which are what Code Block is supporting by default. However, I'm pretty sure that you code configure Code Block to use a specific compiler in a non compliant mode (or simply a non compliant compiler), since it is a flexible IDE; you might well be able to set it up to use Turbo C++, and thus make it compile non ANSI C++. That said, I don't think that Turbo C++ does not support ANSI C++.
Thirdly, Namespaces are a feature of C++, that you have to use if you want to use the standard C++ library, but nothing forces you to otherwise.
(1) the name is a convention, but the function itself is obviously necessary.
Possibly you worked on a very old version of compiler that doesn't implement the C++
specifications completely or in other words it is not conformant to C++
. An old version written during dos era may allow you to do many nasty/non-standard things.
In C++
entire C++ standard library is defined within namespace std
. You must use using
and/or fully qualified name (with scope resolution) to access these.
main
in C++ must return an int
with either of the 2 signatures
int main();
int main(int argc, char *argv[]);
In short for your use cases turbo C++
is doing wrong while Codeblocks
is correct.

- 30,259
- 8
- 73
- 100