Subtle Errors in C++ Programs

I recently stumbled upon a subtle bug in a benchmark code which again reminds me to never use C++ again, if I can. Here’s a buggy snippet from this code (simplified): // BUGGY ostringstream os; int i = 1; os << "foo-" << i << ".dat"; const char *filename = os.str().c_str(); int fd = open(filename, O_RDONLY); You may expect above code to try open a file named foo-1.dat but that’s not what is happening here. [Read More]

Setting up KDE API Documentation

Since last few months, I have been playing around with KDevelop which is a KDE based IDE for C/C++ any many other languages. Its a large C++ codebase and navigating through all the files, classes is quite difficult with usual VI + cscope combination. The most lacking part is a readily accessible KDE API documentation which is almost essential, no matter what component you are working on. There is a KDE API reference site but searching there for every reference is very cumbersome. [Read More]

Anti-tip of the month

Very old but still as relevant… and very interesting too! Directly go to “anti-tip” section of this article. “The moral of the story is: don’t get tricky. C programmers often try to minimize the number of lines of C in their program without consideration for what the compiler will generate. When in doubt, write clear code and give the optimizer a chance to maximize performance. Look at the compiler output. Your code will be easier to debug and probably faster too. [Read More]