C++ has been around for a long time. Almost 20 years have passed since its iso-standardization. With significant changes in the last years, C++ developers need to update their knowledge. ESR Labs provided us with 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.

C++14 drawing
C++14 drawing

To get a feeling for the impact of the changes and the implications for the developers, consider following quote 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 standards. This adaptation cost him an incredible amount of work. To get a first impression, 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 better suited for this. Instead, this blog entry tries to give a different view to the newest standards and present own thoughts on standardization, the situation in our industry and more.

C++ history and current status

Adding object orientation to C was one of the primary goals of Bjarne Stroustrup. Thus he started implementing “C with Classes.” Later it was renamed to C++, one of the most modern 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 its success was the standardization process started in 1998. The following pictures show timeline containing releases in the past and near future.

c++-timeline
c++-timeline

Source: https://isocpp.org/std/status

Initially standardized in 1998 there was little to none change in the next years. Starting in 2005 the official committee kicked off the informally named C++0x. Also, experts in the committee are no magicians, so it took another six years until to get the new standard C++11 published. Containing a tremendous 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 many adoptions of key features of boost into the future releases of the STL.

Workshop Impressions

Nicolai M. Josuttis held the workshop. As a known author of multiple books in the C++ world and a member of the standardization committee, he gave us a great insight into the depths of our primary 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, we compared the performance. Long story short, the new standard provides some excellent performance improvement possibilities. One of the greatest parts 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.

Stakeholder’s wishes

Not only software development industries like automotive need to care about their stakeholders’ needs but also the standardization that 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 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 incredible success, the process itself is not easy. It is entirely possible and is happening that Mr. Stroustrup will not like some features introduced in newest releases. Compared to different open source project policies this is a huge difference. Linus Torvalds, for example, could reject any feature he wants and thus can 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. That 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 mainly due to 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 an enormous tradeoff.”

Read the full article of Herb Sutter here.

Modern world vs. embedded world

I don’t want to generalize, but 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 latest C++ version or even an object-oriented language? One of the main reasons is the compiler. Some of the compilers in within an embedded environment don’t support the fanciest newest features. ESR 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 current 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 web page, which lists the support of new features of typical C++ compilers.
  • Additionally, you should take a look at the C++ core guidelines maintained by Bjarne Stroustrup and Herb Sutter.

Conclusion

On Behalf of the Participants, we would like to thank ESR Labs and Nicolai M. Josuttis for the great learning opportunity. The next step is to evaluate the advantages under embedded constraints.