Merge branch 'davies_liu'

Add changes to make it compile in C++ (e.g. casting after malloc(), spaces wrapping PRI*)