November 2009 Archives

2009-11-09

C++ Pitfalls

As I do no C++ hacking at ETH I have not stumbled upon new input for this blog on my own. So I am very happy that Roker keeps on feeding me.

Today he pointed me at Cay Horstmann's list of C++ pitfalls. Some of the issues have already been covered here but some haven't. I recommend reading it to every C++ developer as this takes less time than learning it the hard way by debugging code. Have fun.

Concerning the iterator issues Cay provides a Safe STL implementation which is supposed to be used as a drop in replacement for the STL during development. It adds state and knowledge about the owner to iterators and uses this information to do runtime checks. If you accidently use your iterators in a wrong way you end up with a comprehensive runtime error instead of a segfault "deep in the bowels of STL code".

I haven't tested Safe STL. If anybody did feel free to send me your experience. I would be glad to blog about it.


Posted by Alexander Bernauer | Permanent Link | Categories: C++

2009-11-09

Catching Integer Overflows in C

Roker pointed me to an article about Catching Integer Overflows in C by Felix von Leitner. It covers some nasty pitfalls of integer arithmetic in C. My absolute favourite is that abs may return a negative number. Comforting to know that C++ inherited this behaviour....

Posted by Alexander Bernauer | Permanent Link | Categories: C++