This page is about the programming languages C and C++. We will collect some information and references that are useful for the creation of simple numerical solutions that are of interest to Azimuth.
We will also collect references to literature, libaries, frameworks etc. that help to create C++ software projects. Another focus is on the know-how of creating large software projects. This is needed in order to write, maintain and understand climate models.
This page should be helpful for everyone who is interested in using C++ in scientific computation, especially on large projects.
C++ has several “standardised versions”:
Original ratified C++ specification.
C++03, an update in 2003 which resolves some of the annoyances in the original specification. Most compilers implement this version.
C++11, a second update in 2011 which adds some dramatic new ideas and functionality which resolve even more of the annoyances and inefficiencies. The latest releases of most compilers provide a mode implementing large parts of C++11, but (as yet) none implement the complete standard.
Unit testing and mocking has become an important technique in software development in Java. C++ has some similar ideas:
These look promising:
Java’s JavaDoc tool has become indispensible. C++ has similar tools:
There are several choices for a compiler on Windows.
Cygwin provides some Unix tools for Windows including the GCC compiler. Note that you will not compile Windows executables this way.
MinGW is a compiler that can compile executables for Windows,
Microsofts C++ compiler has been made available for free.
If you plan to use Microsofts C++ compiler, you can use Microsoft’s Visual Studio 2010 Express as an IDE (integrated development environment).
On Unix-style systems (Linux, BSDs, Apple OSX) there are several options:
GCC (in particular g++) is the main compiler on those systems.
Eclipse (usable on both Windows and Linux) has plugins supporting all three compiler choices. You can find the “Eclipse IDE for C/C++ Developers” available for free on the Eclipse download page.
C++ has a lot more degrees of freedom concerning the organization of source code files than Java, so for coders coming from Java there are some pitfalls. A good book to learn about best practices for large projects is this one:
For setting up a build of a large C++ project, one can use GNU make, of course (TODO: add link). Another possibility is CMake. See the following question on stackoverflow for links to documentation: CMake references.
For CMake there is an Eclipse plugin, CMakeBuilder.
Java has several well established logging frameworks like log4j, also the JDK itself comes with a basic logging framwork. Here is a question about logging frameworks for C++:
Static code analysis tools scan the source code before or after compilation, in order to calculate metrics (like: how many lines of code have a comment?), find common programming errors (like - potiential - null pointer access) or to check if the code adheres to fixed style lines.
Here is a most relevant question about tools for C++ on stackoverflow:
However this is 4 years old. Arguably the clang static analysis tools have progressed significantly since then. The clang approach “attaches” analysis modules to the actual clang compiler, which has the advantage of ensuring that the checker understands the language exactly as well as the compiler. (Checkers with their own parsers often get confused by unusual but valid programming idioms, particularly due to language changes.)
However C++ explicitly avoids requiring certain expensive runtime properties such as array bounds checking so that carefully constructed code does not pay the penalty. (If such checking is always desired it can be acheived using custom classes.) Hence it’s useful to use dynamic observation software periodically during development. Examples include
TODO: performance monitoring (speed, hotspots, memory allocation, memory leaks)
Multithreading functionality has become part of the standard in C++11. Fortunately the leading author has written a book about it:
Unfortunately however it would seem that most compilers have not implemented most of this standard yet, for the GNU GCC see the project page for C++11 support.
Fortunately, Anthony Williams has written a boost library that became the foundation and inspiration of the standadard that one can use instead, see boost thread in the documention of the 1.49 release.
TODO
Boost library of general template classes and algorithms. Everyone seriously using C++ needs to know it.
The Boost C++ Libraries, online documentation by Boris Schäling.
Eigen library of low-level matrix operations.
GSL gnu scientific library, pure C implementation for a lot of numerical algorithms. Poor documentation.
ALGLIB, C++ library with a lot of basic numerical algorithms, lightweigh and easy to include.
Stephen Prata: C++ Primer Plus, 6th edition, Addison-Wesley 2011: General introduction which covers the C++11 Standard.
Nicolai M. Josuttis: The C++ Standard Library: A Tutorial and Reference, 2dn edition, Addison-Wesley, 2012: Introduction to the higher abstraction layer of the C++11 standard.
Martin Reddy: API Design for C++, Morgan Kaufmann; 1st edition 2011
Herb Sutter and Andrei Alexandrescu: C++ Coding Standards: 101 Rules, Guidelines, and Best Practices, Addison-Wesley, 1st edition, 2004
Scott Meyers: Effective C++: 55 Specific Ways to Improve Your Programs and Designs, Addison-Wesley, 3rd edition, 2005
D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, Jeff Cogswell: C++ Cookbook, O’Reilly Media, 1st edition, 2005
David Vandevoorde and Nicolai M. Josuttis: C++ Templates: The Complete Guide, Addison-Wesley, 1st edition 2002
Davide Di Gennaro: Advanced C++ Metaprogramming, CreateSpace, 1st edition, 2011