lagerfeuer

Myths

As I started working in the embedded environment I was astonished that there was so much prejudice against the usage of C++ in embedded programming. Most are based on a wrong understanding of the programming language C++.

 

 

The Myths

lagerfeuer

First, I have to say a few words about the myths about C++ I often heard. Of course, this post reflects my perception. Examples?

  • Templates inflate the code.
  • Objects must live on the heap
  • Exceptions are expensive.
  • C++ is too slow and needs too much memory.
  • C++ is too dangerous in safety-critical systems.
  • You have to program object-oriented in C++.
  • C++ can only be used for applications.
  • The iostream library is too big; the Standard Template Library to slow.

Or to say it in one statement.

=> C++ is a nice toy, but we are dealing with serious challenges.

The list of (pre)judice is long, consisting partially of half-truth and untruth statements often stated by experienced C programmers. I will only refer to the untruth statements. The half-truth statements are, to a significant extent, questions due to the right usage of C++ and, to a small extent, questions of the implementation of the core and the libraries of C++. 

  • Objects must live on the heap.
    • Objects can be created on the stack or at an arbitrary position with the help of placement new.
  • C++ is too dangerous in safety-critical systems.
    • Of course, it depends on the experience of the developer. But whoever uses C strings instead of C++ strings; uses C arrays instead of C++ arrays; or uses macros instead of constant expressions or templates can not argue that C++ is not well suited for safety-critical systems. Honestly, the contrary holds. C++ has a lot to offer in safety-critical systems. 
  • You have to program object-oriented in C++.
    • C++  is a multi-paradigm language. Therefore, you can solve your problem in an object-oriented, structured, functional, generic, or generative style.
  • C++ can only be used for applications.
    • C++ is, for example, used for fire extinguishers, defibrillators, and cars. ARM maintains the current GCC collection with ARM GCC and the gnu toolchain. Therefore, the current g++ compiler is available. The packages that are very frequently used are maintained by ARM for their processors, which are the default architecture for the embedded world.

What’s the reason for the half-truth? I think there are more reasons.

 

Rainer D 6 P2 500x500Modernes C++ Mentoring

  • "Fundamentals for C++ Professionals" (open)
  • "Design Patterns and Architectural Patterns with C++" (open)
  • "C++20: Get the Details" (open)
  • "Concurrency with Modern C++" (open)
  • "Generic Programming (Templates) with C++": October 2024
  • "Embedded Programming with Modern C++": October 2024
  • "Clean Code: Best Practices for Modern C++": March 2025
  • Do you want to stay informed: Subscribe.

     

    • Old C++ compilers
      • The knowledge is based on old C++ compilers of the last millennium. They implement the C++98 standard but they have a large potential for optimization.
    • Training deficit
      • On the one hand, many embedded programmers learned only C. On the other hand, there is no time to experiment with new technologies.
    • Loss of expert state
      • You have to be brave to leave your area as a C expert and continue the next day as a C++ novice.
    • Legacy codebase in C
      • The existing code base is in C therefore is the apparent decision to fix a bug or implement a feature in the first place in C.
    • Many C experts
      • There are many C experts. They are training the novices and becoming leaders.
    • Curse of the monoculture
      • I perceive the embedded world often as a monoculture. I worked for 15 years as a consultant in the automobile area and used about ten languages. On the contrary, I used only three languages in the embedded area. 
    • The pressure of the standard
      • There are a lot of standards that you have to fulfill. The courage to use new technologies seems inversely proportional to the pressure of the standards. 
    • Insufficient knowledge of C++
      • Many developers do have insufficient knowledge of classical C++ and no knowledge of modern C++.

       

    Maybe, I will polarize with this post. But If it helps to make the great features of modern C++ better known in the embedded world, then I want to do it voluntarily. In the next post, I compare the myths with the facts. In particular, I will write about the Technical Report on C++ Performance.

     

     

     

    Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Jozo Leko, John Breland, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Mario Luoni, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Daniel Hufschläger, Alessandro Pezzato, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Michael Dunsky, Leo Goodstadt, John Wiederhirn, Yacob Cohen-Arazi, Florian Tischler, Robin Furness, Michael Young, Holger Detering, Bernd Mühlhaus, Stephen Kelley, Kyle Dean, Tusar Palauri, Juan Dent, George Liao, Daniel Ceperley, Jon T Hess, Stephen Totten, Wolfgang Fütterer, Matthias Grün, Phillip Diekmann, Ben Atakora, Ann Shatoff, Rob North, Bhavith C Achar, Marco Parri Empoli, Philipp Lenk, Charles-Jianye Chen, Keith Jeffery,and Matt Godbolt.

    Thanks, in particular, to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, John Nebel, Mipko, Alicja Kaminska, Slavko Radman, and David Poole.

    My special thanks to Embarcadero
    My special thanks to PVS-Studio
    My special thanks to Tipi.build 
    My special thanks to Take Up Code
    My special thanks to SHAVEDYAKS

    Modernes C++ GmbH

    Modernes C++ Mentoring (English)

    Do you want to stay informed about my mentoring programs? Subscribe Here

    Rainer Grimm
    Yalovastraße 20
    72108 Rottenburg

    Mobil: +49 176 5506 5086
    Mail: schulung@ModernesCpp.de
    Mentoring: www.ModernesCpp.org

    Modernes C++ Mentoring,

     

     

    0 replies

    Leave a Reply

    Want to join the discussion?
    Feel free to contribute!

    Leave a Reply

    Your email address will not be published. Required fields are marked *