{"id":4965,"date":"2016-10-02T08:25:08","date_gmt":"2016-10-02T08:25:08","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/myths\/"},"modified":"2023-06-26T12:40:51","modified_gmt":"2023-06-26T12:40:51","slug":"myths","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/myths\/","title":{"rendered":"Myths"},"content":{"rendered":"<p>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++.<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h2>The Myths<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4964\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/lagerfeuer.jpeg\" alt=\"lagerfeuer\" width=\"700\" height=\"466\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/lagerfeuer.jpeg 700w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/lagerfeuer-300x200.jpeg 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>First, I have to say a few words about the myths about C++ I often heard. Of course, this post reflects my perception. Examples?<\/p>\n<ul>\n<li>Templates inflate the code.<\/li>\n<li>Objects must live on the heap<\/li>\n<li>Exceptions are expensive.<\/li>\n<li>C++ is too slow and needs too much memory.<\/li>\n<li>C++ is too dangerous in safety-critical systems.<\/li>\n<li>You have to program object-oriented in C++.<\/li>\n<li>C++ can only be used for applications.<\/li>\n<li>The iostream library is too big; the Standard Template Library to slow.<\/li>\n<\/ul>\n<p>Or to say it in one statement.<\/p>\n<p><span style=\"font-size: 14pt;\"><strong><span style=\"color: #ff0000;\">=&gt;<\/span><\/strong> <\/span> C++ is a nice toy, but we are dealing with serious challenges.<\/p>\n<p>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++.&nbsp;<\/p>\n<ul>\n<li>Objects must live on the heap.\n<ul>\n<li>Objects can be created on the stack or at an arbitrary position with the help of <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/new\">placement new.<\/a><span style=\"font-family: courier new,courier;\"><\/span><\/li>\n<\/ul>\n<\/li>\n<li>C++ is too dangerous in safety-critical systems.\n<ul>\n<li>Of course, it depends on the experience of the developer. But whoever uses C strings instead of C++ strings;&nbsp;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.&nbsp;<\/li>\n<\/ul>\n<\/li>\n<li>You have to program object-oriented in C++.\n<ul>\n<li>C++&nbsp; is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Programming_paradigm\">multi-paradigm language<\/a>. Therefore, you can solve your problem in an object-oriented, structured, functional, generic, or generative style.<\/li>\n<\/ul>\n<\/li>\n<li>C++ can only be used for applications.\n<ul>\n<li>C++ is, for example, used for fire extinguishers, defibrillators, and cars. ARM maintains the current GCC collection with ARM GCC and the <a href=\"https:\/\/de.wikipedia.org\/wiki\/GNU_Toolchain\">gnu toolchain<\/a>. 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.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>What&#8217;s the reason for the half-truth? I think there are more reasons.<\/p>\n<ul>\n<li>Old C++ compilers\n<ul>\n<li>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.<\/li>\n<\/ul>\n<\/li>\n<li>Training deficit\n<ul>\n<li>On the one hand, many embedded programmers learned only C. On the other hand, there is no time to experiment with new technologies.<\/li>\n<\/ul>\n<\/li>\n<li>Loss of expert state\n<ul>\n<li>You have to be brave to leave your area as a C expert and continue the next day as a C++ novice.<\/li>\n<\/ul>\n<\/li>\n<li>Legacy codebase in C\n<ul>\n<li>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.<\/li>\n<\/ul>\n<\/li>\n<li>Many C experts\n<ul>\n<li>There are many C experts. They are training the novices and becoming leaders.<\/li>\n<\/ul>\n<\/li>\n<li>Curse of the monoculture\n<ul>\n<li>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.&nbsp;<\/li>\n<\/ul>\n<\/li>\n<li>The pressure of the standard\n<ul>\n<li>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.&nbsp;<\/li>\n<\/ul>\n<\/li>\n<li>Insufficient knowledge of C++\n<ul>\n<li>Many developers do have insufficient knowledge of classical C++ and no knowledge of modern C++.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p>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 <a href=\"https:\/\/www.modernescpp.com\/index.php\/facts\">next post<\/a>, I compare the myths with the facts. In particular, I will write about the <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/TR18015.pdf\">Technical Report on C++ Performance.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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++. &nbsp;<\/p>\n","protected":false},"author":21,"featured_media":4964,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[364],"tags":[467],"class_list":["post-4965","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded","tag-myths"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=4965"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4965\/revisions"}],"predecessor-version":[{"id":6941,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4965\/revisions\/6941"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/4964"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=4965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=4965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=4965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}