Make it work in C++

Hi,

We are using this in dgen-sdl, which is written in C++. You will need minor preprocessor magic.

Cheers for you code -- we like it.