views:

402

answers:

3

Normally I program in C# but have been forced to do some work in C++. It seems that the integration with Visual Studio (2008) is really poor compared to C# but I was wondering if there are any good tools, plugins or configurations that can improve the situation.

Another post pointed out the program Visual Assist X, which at least helps with some things such as refactoring (though it is a bit expensive for me). My major problem is, though, that the compile errors give little clue about what is wrong and I spend most of my time figuring out what I did wrong. It just feels like it is possibly to statically check for a lot more errors than VS does out of the box. And why doesn't it provide the blue underlines as with C#, that shouldn't be too hard?!

I realize that half the problem is just the fact that I am new to C++ but I really feel that it can be unreasonably hard to get a program to compile. Are there any tools of this sort out there or are my demands too high?

+7  A: 

I think there are two possibilities: 1) either you're trying out C++ stuff that is waaay over your knowledge (and consequently, you don't know what you did wrong and how to interpret error messages), 2) you have too high expectations.

A hint: many subsequent errors are caused by the first error. When I get a huge list of errors, I usually correct just the first error and recompile. You'd be amazed how much garbage (in terms of error messages) a missing delimiter or type declaration could produce :)

It is difficult to syntactically analyze a C++ program before compilation mainly for two reasons: 1) the C++ grammar is context-dependent, 2) templates are Turing-complete (think of them as of a functional programming language with a weird syntax).

zvrba
It's pretty basic stuff I'm playing with so it's probably option 2. Actually, I feared that it might be something tied to the nature of the language as you suggest.
Morten Christiansen
+4  A: 

My suggestions:

  • If you want more features like you get in C#, get VisualAssist X, and learn how to use it. It isn't free but it can save you a lot of time.
  • Set your warning level high (this will initially generate more compile-errors but as you fix them, you'll get a feel for common mistakes).
  • Set warning as error so you don't get in the habit of ignoring warnings.
  • To understand compile errors, use Google (don't waste your time with the help system) to search on warning error numbers (they look like this: C4127).
  • Avoid templates until you get your code compiling without errors using the above methods. If you don't know templates well, study! Get some books, do some tutorials and start small. Template compile errors are notoriously hard to figure out. Visual C++ 2008 has much better error messages than previous versions but it's still hard.
  • If you start doing templates in earnest, get a wide-screen monitor (maybe even two) to make reading the verbose errors easier.
jwfearn
Why was I down voted?
jwfearn
Because he/she didn't understand what you wrote? I up-voted, by the way.
Johann Gerell
Thank you, those are most useful advice :)
Morten Christiansen
Thanks Johann and Morten.
jwfearn
+3  A: 

+1 for Visual Assist, maybe not now - but when you turn the hobby into a profession you will need it.

In my experience, the diagnsotics are already much better than in VC6, but you will need to "learn" their true meaning as part of learning the IDE.

Static checking of C++ is much more complicated than C#, due to the build mode, and the incredibly more complex language. PC-Lint (best together with Visual Lint to integrate it into the IDE) is the canonical static analysis. Not cheap either, though...

The C++ standard sometimes reads like scripture, but without a trained preacher to interpret it. One excellent interpreter is Marshal Cline with his C++ FAQ. Note that the online FAQ, while extensive, covers much less than the book.

What helped me a lot understanding complex error messages is trying to reproduce the problem in a smaller environment - but then, there was no internet back then...

peterchen