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

Using C++ templates for size-based type selection

The standardisation of size-specific integer types in C/C++ is extremely useful for portability. That is, when you use types like uint16_t and int32_t, you know exactly what size of data type you’re getting (assuming your compiler supports it, which is usually the case unless you’re working with very specialist/embedded systems). This isn’t the case with the more traditional types like short and int whose sizes can vary from one compiler to another. However, the size is obviously part of the type name, meaning you need to alter declarations directly if you want to use a type of a different size.

Using the std::conditional template from C++11 lets you change this. Instead, you can have a template parameter which specifies the size you want (e.g. in bytes). The corresponding type declaration can be automatically deduced from there.
Read more Using C++ templates for size-based type selection

Remote control bug on first level of LEGO Batman

I bought “LEGO Batman: The Videogame” for PC today (it was going cheap on Steam!). In the first level, I got stuck for a while because of an odd bug. You’re supposed to remote control a little green car, but for some reason it wouldn’t always move.

In summary, the fix which worked for me was to enable Vertical Sync in the game’s graphics settings. More details below.

LEGO Batman screenshot

Read more Remote control bug on first level of LEGO Batman

Tagged with

Order of parameter evaluation in C++

The low-level details of how data gets passed into a function are often overlooked by programmers. We obviously care about passing parameters by value vs. reference, and perhaps also by copy vs. move, but it’s easy to ignore anything deeper than that.

With C++ in particular, this can cause an unexpected problem regarding the order in which things actually happen. In this post, we’ll look at what can go wrong, and how to deal with it.
Read more Order of parameter evaluation in C++

Tagged with

Prevent Word from putting page breaks in table rows

If you’re using large tables in Word, you may sometimes find that they run across more than one page. Quite often, the page break occurs inside a row, which means the row gets split across two pages. To the person reading it, this can potentially make it look like two separate rows, which is frustrating.

The usual “Keep lines together” paragraph options don’t prevent this. You need to set the table properties instead.
Read more Prevent Word from putting page breaks in table rows

Changing the emulation mode of the Microsoft Web Browser ActiveX control

I’ve been working on an MFC project which embeds a basic web-browser component in a dialog, in the form of a Microsoft Web Browser ActiveX component. (I know… these are ancient technologies… but sometimes you’ve got to work with what’s available on a project!)

Technically, the control hooks into whatever version of Internet Explorer (IE) you’re running on the system. However, it always seemed to fall-back on IE7 emulation mode for us, meaning a lot of our modern standards-compliant HTML wouldn’t work properly. Thankfully, there is a way to fix this problem, although it’s far from obvious!

Read more Changing the emulation mode of the Microsoft Web Browser ActiveX control

New Arduino Q&A site online

If you’re interested in any Arduino boards then I recommend checking-out the new Arduino Q&A site over on Stack Exchange. (It’s totally free to use.)

As with most Stack Exchange sites, it was in private beta for a couple of weeks to get it started. It’s now gone into public beta, which means it’s fully functional and anybody can join in. It’s a great place to go if you need help with specific Arduino problems, or if you’ve got some awesome expertise that you want to share.