views:

510

answers:

3

I'm learning C++ and when I was testing the Microsoft Visual C++ 2008 Express and Eclipse Ganymede, but with the g++ compiler as default, I've noted that a same code in VC++ get some errors and in g++ compile normally, without errors or warnings and execute normally, but I want to know what is the difference between VC++ syntax and g++ syntax? Thanks!

+4  A: 

It's a very broad topic. Both compilers are broadly ISO C++ conformant with some exceptions, but those exceptions may differ (for example, VC++ treats throw specifier on functions in a non-standard way, while g++ is standard compliant in that regard). In addition, both compilers provide a fairly large number of extensions, which are mostly mutually incompatible (e.g. VC++ __property and __interface, or g++ typeof and computed goto). In general, the best advice here is to consult the documentation of either product. If you have any specific code that you're having problems with, and would like to know why it does compile with one but not the other, then it would be possible to answer in more detail.

Pavel Minaev
Thanks, your answer is very good!
Nathan Campos
+12  A: 

Can't comment because I'm new (reputation isn't 50 yet), but here's another Stack Overflow question that deals with a similar topic:

http://stackoverflow.com/questions/1150723/compiling-differences-in-visual-c-and-nix-enviroments

Umsd
+1 to get to 49 so you can almost comment
Remus Rusanu
Ah, thank you :)
Umsd
+1 for the answer and because now you can comment!
Nathan Campos
+1 for a good answer, +1 your comment just for heck of it
caspin
+1  A: 

Please add this to Pavel's answer:

If you are developing a cross platform product, use g++ (MingW) and stick to the C++ standard. Use POSIX compliant APIs provided by MingW where the standard facilities does not serve the purpose. An executable built using MingW does not need a special runtime to be installed on the target system, but VC++ 2008 requires that. So deployment is simpler with MingW applications.

An advantage of VC++ is its great IDE. The Microsoft compiler seems to perform some Windows specific optimizations as well.

Still, MingW complemented with the CodeBlocks IDE can give you a great, free, cross-platform C++ development environment.

Vijay Mathew
Also the NetBeans IDE give you great development environment.
Kamran