Workaround for nvcc pthread issue

I recently upgraded various pieces of software on my work PC. Afterwards, I found that our C++/CUDA projects wouldn’t build. The following error was reported:

nvcc fatal   : Unknown option 'pthread'

I was attempting to build it in CLion 2018.2.5 using the bundled CMake 3.12.2. My OS is Ubuntu 18.04 and I’m using CUDA 9.1.

So far, I haven’t been able to find a proper solution. However, I have found a simple workaround. If you know of a better solution then please let me know in the comments!

Read more Workaround for nvcc pthread issue

Comfort Curve Keyboard 3000 bug on Windows 10

I’ve been using the Microsoft Comfort Curve Keyboard 3000 for a number of years, and it’s mostly served me very well. However, since upgrading to Windows 10, the keyboard has shown an annoying bug. If I leave it for a few seconds without pressing anything then the keyboard seems to shut down. If any keys are held down at that point then the OS doesn’t notice when they get released. The result is it thinks the keys are still held until I pressed and release them again. Sami Korhonen has made a YouTube video demonstrating the same problem.

Read more Comfort Curve Keyboard 3000 bug on Windows 10

Why Python 3 doesn’t write the Unicode BOM

I’ve been using Python scripts to automatically edit and output Windows Resource files (*.rc) for C++ projects in Visual Studio 2013. When handling Unicode, Windows and Visual Studio always want little endian UTF-16 encoding, and the resource file should always start with the Unicode BOM (Byte Order Mark). However, despite the promises in the documentation, I found that Python wasn’t outputting the BOM automatically.

I nearly resorted to outputting it manually, but as is often the case with Python, the correct approach is simpler than it seems. Read more Why Python 3 doesn’t write the Unicode BOM

Output file encoding in Python 3

Unicode is becoming very widespread now (for good reason), and one of the great benefits of Python 3.x is that it handles Unicode natively. There are different ways to represent Unicode though, so how do you set the file encoding in Python when you’re writing out to file?

It’s not immediately obvious from some of the official documentation, but thankfully it’s not complicated. I’ll give a quick overview in this post. Read more Output file encoding in Python 3

Generate UTF-8 dictionaries using gettext

I’ve been setting up localisation for an application using a combination of tools: the Boost Locale library, and the widely used gettext tools. I’m wanting to work entirely in UTF-8 because it should be suitable for pretty much any language we’re likely to need, and it should hopefully avoid problems of mixing encodings. However, I found that the tools kept falling-back to outdated character sets instead.

Fortunately, there’s a fairly easy solution which I’ll outline quickly in this post. Read more Generate UTF-8 dictionaries using gettext

Decimal places in a floating point number

Floating point numbers are a mainstay of programming in areas such as games, graphics, and simulation. On the whole, they are easy and intuitive to use. However, they have certain quirks and issues to be aware of. For example, their representation is inherently flexible and often approximate. This means there’s no definitive answer to the question of how many decimal places they can hold.

By looking at the way floating point numbers are stored, it’s possible to understand why this happens, and what precision is likely to be available. Hypothetically, it’s possible under certain circumstances to get up to about 45 decimal places in a C++ float, and 324 in a double. However, as we’ll see in this post, it depends on context.
Read more Decimal places in a floating point number

Emit audible warning from a batch script

Windows Batch (*.bat) scripting is archaic and painful, but occasionally useful for quick bits of environment setup. It’s not always obvious to the user when something has gone wrong though as it’s easy to lose the information amidst other text which scrolls by. An audible warning can be a useful alternative to draw attention to a problem.
Read more Emit audible warning from a batch script

C++ constexpr functions

I’ve been very excited to see that Visual Studio 2015 supports the constexpr keyword in C++. It was introduced in the C++11 standard, and is being taken further in upcoming revisions.

There are a number of uses for the keyword, but the one which excites me the most is using it for writing functions which can be executed during compilation, potentially saving a lot of runtime overhead. In this post, I’ll show a couple of quick examples.
Read more C++ constexpr functions