Exceptions & namespaces

Started by
14 comments, last by MaulingMonkey 17 years, 6 months ago
I'm still using VC6 at home because it's all I have. I've never had issues programming C++, but maybe I haven't been using the features it's missing. Is there a list of the problems with VC6?

I had used the 2003 toolkit in the past while still using the VC6 GUI, but I couldn't develop MFC with that.

I'm going to try the 2005 Express edition out as well.
Advertisement
Off the top of my head, proper variable scoping in for loops, and partial template specialisation are two big things missing from VC6 (although there are many others).

You would be more likely to run into trouble if you use certain libraries that make heavy use of templates.

Some features of the boost libraries, for example, are unsupported under VC6, but supported on VC .NET 2003 and 2005. Later versions of the boost::spirit parser library for example, will not compile at all under Visual Studio compilers older than Visual Studio 2003. Some boost libraries have nicer features available when you use standard conforming compilers, compared to compilers like Visual Studio 6 or 2002. (see boost::function for an example)

I've got Visual Studio 2002 professional, and I'm still using VC2005 Express at the moment, because the compiler is just so much better than Visual Studio 2002, that I don't mind using the express edition until I can find some spare cash to get the professional edition.
XD
In fact, I can get all Microsoft stuff, as well as softwares like MatLab for free at college. We even have a Microsoft Lab (and I´ve been working there as an intern for almost a month¬¬)...but then, my laziness got the best out of me and I asked my college friend for the Visual C++ she had so I wouldn´t have to go there this weekend. Not the best of ideas it seems >.<"
But, hey, I like using emacs and g++, nothing bothers me any longer XD
Quote:Original post by Carolina
1. Is using exceptions the best way to make my code handle errors properly? I´m used to writing conditionals galore to catch them, but maybe exceptions provide better performance?

That depends on the error. Sometimes, yes, sometimes, no. If you search the forums, there are a number of threads discussing when they're appropriate.
Quote:Original post by Carolina
2. If so, are there any pre-built exceptions on Visual C++ 6.0? Or do I have to write an exception class? I know when using .NET Framework you can do both, but is that something only for .NET or a standard C++ feature?

C++ lets you throw pretty much anything as an exception. throw 2; works just fine, although you shouldn't ever do that. The standard library does provide a number of exceptions to cover its own needs, but you're free to create your own if you want. A quick google yields this if you're interested in the standard ones.
Quote:Original post by Carolina
3. I´m using namespaces to separate groups of functions with different general objectives on my code. Is this a good thing in terms of organization, or should I divide them in classes as static functions (I suppose instantiating a class just to use a function, the class having no attributes at all, is a dumb thing to do)? What´s the underlying difference between them?

A 'static' class [one with just static members] offers no advantage over a namespace, and in general you should prefer namespaces in those circumstances. Whether or not such namespaces are a good organization depends on what you're doing, but don't shy away from them just because you read somewhere that freestanding functions are bad.

CM
Quote:Original post by Carolina
1. Is using exceptions the best way to make my code handle errors properly? I´m used to writing conditionals galore to catch them, but maybe exceptions provide better performance?


As far as I know, the performance is something like this:
Exceptions are basically free *when they're not thrown*
But they're a hell of a lot slower than an if-statement once they are thrown.

So from a pure performance point of view, you should only use them when you don't expect them to be thrown, but it might possibly happen once in a while.

And luckily, from a design point of view, I'd do much the same. Use exceptions for, well, exceptional errors. Things that aren't ever supposed to happen, but sometimes happen anyway.
Quote:Original post by Spoonbender
Quote:Original post by Carolina
1. Is using exceptions the best way to make my code handle errors properly? I´m used to writing conditionals galore to catch them, but maybe exceptions provide better performance?


As far as I know, the performance is something like this:
Exceptions are basically free *when they're not thrown*
But they're a hell of a lot slower than an if-statement once they are thrown.


Which is still pretty darn fast. I recently posted some benchmarks of this.

Relevant release mode statistics using VS2005 Standard on my 2.4Ghz P4:

~126 thousand exceptions thrown, caught, and tallied/second.
~1.686 billion (american - 109) try/catch blocks entered and left/second.

This topic is closed to new replies.

Advertisement