C++ related things

So, I'm a (pure) Mathemtician with an on/off (mostly off, until recently) interest in computer programming. Why would I not like C++?

C++ Books

Design Patterns: Elements of Reusable Object-Oriented Software

By Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides [Leeds] [Amazon] [Foyles]

The "classic" book on software design patterns, targetting mainly C++. I really liked this book: it's written in the sort of academic style that I'm used to, and it formalised and explained many ideas I've been seeing in other books, and seeing when reading other people's code.

I guess I worry about the age of the book (20 years seems a long time in software development). Next up is to read Head First Design Patterns.

Other links:

More Effective C++

By Scott Meyers [Leeds] [Amazon] [Foyles: Out of stock]

Rather old, but still, I found, a beautiful read (but which I mean, I could read this in bed, and make sense of it, but I also never felt the pace was tedious, nor the language verbose.) It is presented as a series of "items", each covering some aspect of C++. Some of these are rather out of date: talk of the STL being something strange, for example! I think also some items would these days be covered under the term "design patterns" (e.g. Proxy Classes).

I'm not quite sure about the re-readability. It would be very nice to have a rather short reference: perhaps a list of the titles and a paragraph or two summary. A quick search online didn't find such a thing.

Scott Meyers has an interesting website: Scott Meyers: Books which contains details of a version of Effective C++ for C++11/14.

Practical C++ Programming

By Steve Oualline [Leeds] [Amazon]

Not a book for me. It's somewhat an introduction (although many online reviews suggest that if you are a beginner, it's hard work) and barely touches on more advanced features. However, I think the real issue is how old it is. Today, templated just work. We have C++11. Compilers and pretty good at optimising. You have a good standard library. The book dedicates just a short chapter to templates, and some of that is around practical issues about getting the compiler to work. There are also some scathing reviews on the O'Reilly website.

In the book's defense, it does touch upon some software engineering issues, which is nice to see.

G++ 64-bits on Windows

This is a very ideosyncratic guide to getting G++ working on Windows, using Mingw and the mingw-w64 project. Works on my machine, Windows 7, October 2014.

  • MinGW-w64 -- Offical project page.
  • I want the lastest G++ version, which means I have no choice but to use the "Mingw-builds project". Sadly, the installer fails on the download part with a very cryptic error code.
  • You can manually download the correct file: the best place to start looking seems to be SourceForge link.
  • The works, but the "threads-win32" seems not to do what I want: provide a working version of the C++11 header, etc.
  • However, the "threads-posix" does work! At least, for a console application not using anything fancy like 3rd party DLLs. That's enough for me for now...
  • A tip of the hat to Oldish post on Eclipse and Mingw
  • The MinGW-w64 distribution doesn't by default come with MSYS, which is useful for building linux based projects. You can download a pre-built copy from SourceForge, MinGW-w64.

Should probably do this again with SEH exception handling, not SJLJ.

Notes on threads

  • pthread vs mthreads -- Some discussion. Should probably use -mthreads.
  • async() weirdness -- Some discussion about how the current g++ implementation of async() doesn't start a separate thread. You need to pass std::launch::async manually.

Building GMP

  • On Windows 7, Mingw-w64. Firstly install MSYS, so we have a working copy of bash and its friends.
  • Download and unpack the gmp source, navigate to this directory, and then run bash.
  • ./configure --enable-cxx
  • Wait...
  • make
  • Wait...
  • To avoid errors, make sure the absolute path has no spaces in...
  • Copy gmp.h and gmpxx.h to mingw/x86_64-w64-mingw32/include/ where mingw is the base directory for your MINGW install.
  • Copy libgmp.a (found in the .libs directory) to mingw/x86_64-w64-mingw32/lib/
  • Now you can compiler gmp code; remember to link with -lgmp for C files, and with -lgmpxx -lgmp for C++ files.