c++

An Introduction to CTest

I’ve seen a lot of people (I’m looking at you Daniel Lemire) praise newer languages like Go, which makes me sad as a C++ programmer. Well, that’s until I realise that most of the features touted could be easily incorporated in C++ with just a bit of elbow grease. In this post, I’ll show how to add an automated testing system using CTest.

A bug in how GCC handles constructors

Some days ago, I became aware of a bug in GCC that has apparently existed since 2015. As this is a bug that deals with memory leaks, it is fairly serious. In this case, I really don’t want to re-post the entire content of the source, so I will only list my experiments with reproducing the bug once I became aware of it. C++ assumes that if a constructor fails, then no memory is allocated for the object at all.

PSA: Don't use std::rand()

With the <random> header in C++11 onwards, there really is no reason to use std::rand() to generate random numbers. In fact, using std::rand() could be really harmful.

On writing platform-independent code (or why I like the new C++)

I use Linux when I work from home, I’m forced to use a Mac at work (well, I boot up a virtual Linux OS), and I use Windows when I just want to goof around with my computer. So, while most of my work is done on Linux, it’s imperative that my code work on all platforms; just because I could use any of the three. Traditionally, C required multiple versions of code, protected by #ifdefs.