C++ been around for a long time. Since it’s iso-standardization almost 20 years have past. With major changes in the last years, C++ developers need to update their knowledge. E.S.R. Labs gave us a great opportunity to do that. Within a 3-day workshop by Nicolai M. Josuttis we learned the newest and hottest features of C++11/14.
To get a feel about the impact of the changes and the implication to the developers consider following cite of the master himself, Mr. Stroustrup: ” C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever”. Mr. Josuttis adapted his book “The C++ Standard Library – A Tutorial and Reference” to the new standard and it cost him an incredible amount of work to do so. To get a first look, just compare vector.h from C++98 to the version from C++11.
This article gives an impression about C++11/14. Different to other articles about the new standard, this one is not going into technical details. Multiple books and sites are definitely better suited for this. Instead this blog entry tries to give a different view to the newest standards and present own thoughts on standardization, situation in our industry and more.
C++ history and current status
Adding object orientation to C was one of the main goals of Bjarne Stroustrup. Thus he started implementing “C with Classes”. Later it was renamed to C++, one of the most popular general purpose languages ever. If you are curious about some real world applications that use C++, you can take a look at C++ applications.
Contributing to it’s success was the standardization process started in 1998. The following pictures shows timeline containing releases in the past and near future.
Initially standardized in 1998 there was little to none change in the next years. Starting in 2005 the standard committee kicked off the informally named C++0x. Also experts in the committee are no magicians, so it took another six years until the new standard C++11 was published. Containing an huge amount of changes and new features, this release impacts the popularity of C++. While C++14 was a minor release, the current project C++17 is going to introduce new features again. Highly influenced by the boost library we will see multiple adoptions of key features of boost into the future releases of the STL.
The workshop was held by Nicolai M. Josuttis. As a known author of multiple books in the C++ world and member of the standardization committee, he gave us a great insight into the deeps of our main programming language. Switching between examples and theory helped us to understand the impact of the newest version of this language. During coding demos, regular C++03 source code was transformed step-by-step to new fancy looking C++11/14 compliant code. After each change the performance was compared. Long story short, the new standard provides some nice performance improvement possibilities. One of the greatest part of this workshop, was the implications for different developers. Divided into application developer, class designer and generic programmer seeing the impact of the new standard for our work was well summarized. Last but not least we got some insights about the standardization process itself including challenges and possibilities.
Not only software development industries like automotive need to care about their stakeholders needs, also the standardization is impacted by it. Imagine you sit in a giant conference room discussing possible features and changes in new versions of C++. Sounds good right? Let’s take a closer look and check if it is really that fun.
Reasons why C++ standardization is hard
- No ultimate single instance that makes critical decisions.
- If the compiler company doesn’t want it, throw it away.
- Backward compatibility.
Although the standardization led C++ to an incredible success, the process itself is not easy. It is totally possible and is actually happening, that some features that are introduced in newest releases are not liked by Mr. Stroustrup. Compared to different open source project policies this is huge difference. Linus Torvalds for example could reject any feature he want and thus is able to decide critical issues by himself.
With a huge amount of ideas from different people there is also the counterpart in the compiler companies. Doesn’t matter how great your idea is, if the compiler doesn’t support it, you lost the battle. By the end of the day you need to convince your stakeholder like in any other industry.
And the last point is that backward compatibility is one goal of the whole development. This leads to some interesting and confusing constructs over the time. Herb Sutter said following about the constraints of compatibility.
“Yes, C++ is complex and the complexity is largely because of C compatibility. I agree with Bjarne that there’s a small language struggling to get out — I’ve participated in private experiments to specify such a language, and you can do it in well under half the complexity of C++ without losing the expressivity and flexibility of C++. However, it does require changes to syntax (mainly) and semantics (secondarily) that amount to making it a new language, which makes it a massive breaking change for programs (where existing code doesn’t compile and would need to be rewritten manually or with a tool) and programmers (where existing developers need retraining). That’s a very big tradeoff.”
Read the full article of Herb Sutter here.
Modern world vs. embedded world
I don’t want to generalize, but the our beloved embedded industry is somehow lagging behind when it comes to the newest trends in software development. Just ask yourself, is my embedded company using the newest C++ version or even an object-oriented-language? One of the main reasons is the compiler. Some of the compilers in an embedded environment doesn’t support the fanciest newest features. E.S.R. Labs for example uses the Diab-Compiler, which has currently no support for C++11/14.
Moving to C++ 11 / 14
- Is there a possibility to transform my old C++ code to modern C++11/14 code? Yes, try the modernizer by clang and evaluate for yourself.
- Different C++ compilers support different features. Following website provides information about testing recommendations regarding new features. Also you could check following website, that list the support of new features of common C++ compilers.
- Additionally you should take a look at the C++ core guidelines maintained by Bjarne Stroustrup and Herb Sutter.
On Behalf of the Participants we would like to thank E.S.R. Labs and Nicolai M. Josuttis for the great learning opportunity. The next step is to evaluate the advantages under embedded constraints.