{"id":1339,"date":"2018-12-23T11:15:54","date_gmt":"2018-12-23T05:45:54","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1339"},"modified":"2018-12-23T11:22:00","modified_gmt":"2018-12-23T05:52:00","slug":"book-review-real-time-c","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/23\/book-review-real-time-c\/","title":{"rendered":"Book Review: Real-Time C++"},"content":{"rendered":"<p><em><strong>Title: Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming<\/strong><\/em><\/p>\n<p><em><strong>Author: Christopher Kormanyos<\/strong><\/em><\/p>\n<p><em><strong>Publisher: Springer-Verlag<\/strong><\/em><\/p>\n<p><em><strong>Year: 2018 (Third Edition)<\/strong><\/em><\/p>\n<p>It was the title of this book which caught my attention a few weeks ago and I decided to invest in it. I am not in to real-time software development these days, but I always welcome material that enhances my knowledge of C++, and software design in general.<span class=\"Apple-converted-space\">\u00a0 <\/span>This is the third edition of the book that has been updated to include material on C++17. After reading the book, I realise that the book is more about C++, touching upon microcontroller programming in a few chapters and with very little discussion on real-time programming issues (although many chapters use the words <em><strong>real-time<\/strong><\/em> in the title). Sure, there are overlapping concerns between microcontroller programming and real-time programming, but real-time programming is a much more complex subject involving not just resource constraints, but more importantly, time constraints and safety-criticality as well. Sadly, this book does not address the latter.<\/p>\n<p>An embedded system need not be a real-time system. See <a href=\"https:\/\/www.quora.com\/Is-there-any-embedded-system-that-is-not-a-real-time-system\" target=\"_blank\" rel=\"noopener\"><em><strong>this<\/strong><\/em><\/a>\u00a0and <em><strong><a href=\"https:\/\/www.embedded.com\/design\/programming-languages-and-tools\/4429790\/How-to-make-C--more-real-time-friendly\" target=\"_blank\" rel=\"noopener\">this<\/a><\/strong><\/em>. Watch this <a href=\"https:\/\/medias.ircam.fr\/x528a26\" target=\"_blank\" rel=\"noopener\"><em><strong>video<\/strong><\/em><\/a>\u00a0if you are interested to know the basic concepts of real-time programming.<\/p>\n<p>Chapter 1 starts with a simple C++ class for controlling an LED in a circuit. The author uses the example to introduce some key C++ concepts including class members and namespaces. While explaining the process of initialising <em><strong>const<\/strong><\/em> member variables, he writes as follows:<\/p>\n<blockquote><p><span style=\"color: #0000ff;\">\u201cConstant member variables <em><strong>must <\/strong><\/em>be initialized in the constructor initialization list. Non-constant member variables <strong><i>should <\/i><\/strong>be initialized in the constructor initialization list. \u201c<\/span><\/p><\/blockquote>\n<p>The author seems to be playing with words here.\u00a0Such a piece of text might be appropriate in a literary context, but not in a programmer\u2019s book! Hope you understand what he is getting at.<\/p>\n<p>Chapter 2 discusses the example of programming a simple solderless prototyping board to flash an LED. In the process, the author shows the different steps for compiling C++ code and transferring it to the board.<\/p>\n<p>The 3rd chapter is titled <em><strong>An Easy Jump Start in Real-Time C++<\/strong><\/em>. This is just an overview of the common topics in C++. Two sections namely, 3.14 (<em><strong>atomic_load()<\/strong> <strong>and<\/strong><\/em> <em><strong>atomic_store()<\/strong><\/em>) and 3.18 (<em><strong>Using<\/strong><\/em> <em><strong>alignof<\/strong> <strong>and<\/strong><\/em> <em><strong>alignas<\/strong><\/em>), are useful in the context of embedded programming, but the other sections are only of general interest.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>The 4th chapter is <em><strong>Object-Oriented Techniques for Microcontrollers<\/strong><\/em>. Here the author covers the basics of inheritance and dynamic binding. The chapter includes sections on how to define an abstract class,<span class=\"Apple-converted-space\">\u00a0 <\/span>non-copyable classes, constant member functions, and class friendship.<\/p>\n<p>Chapter 5 on <em><strong>C++ Templates for Microcontrollers<\/strong><\/em> covers the basics of templates with some examples in the context of microcontrollers.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Interestingly, Chapter 6 is titled <em><strong>Optimized C++ Programming for Microcontrollers<\/strong><\/em>, and contains 20 <em><strong>tips<\/strong><\/em> for writing good code. While some of the tips make sense (and some of them have no impact on performance), I was stumped by two tips in the list:<\/p>\n<blockquote><p><span style=\"color: #0000ff;\"><em><strong>6.8: Use Comments Sparingly.<\/strong><\/em>\u00a0<\/span><\/p>\n<p><span style=\"color: #0000ff;\"><em><strong>6.18: Use Lambda Expressions.<\/strong><\/em>\u00a0<\/span><\/p><\/blockquote>\n<p>Regarding 6.8, I don\u2019t know how many would approve of this tip! Also, what impact does this have on performance? And what about 6.18? The reason the author gives is that using lambdas can result in considerable code saving and can improve performance. Well, this is not always true. See <a href=\"https:\/\/www.quora.com\/Why-is-C-lambda-faster-than-a-normal-function-Is-it-good-to-replace-all-the-functions-with-lambdas\" target=\"_blank\" rel=\"noopener\"><em><strong>this<\/strong><\/em><\/a> discussion.\u00a0It would have been better if the author had given specific scenarios where lambdas make sense and where they do not, instead of making a sweeping recommendation in their favour. Having said that, however, tips such as <em><strong>Use Native Integer Types<\/strong><\/em> (6.10) and <em><strong>Consider ROM-ability<\/strong><\/em> (6.14) definitely make sense.<\/p>\n<p>In Chapter 7, the author explains how to write C++ code to access hardware addresses, especially the port addresses. He prefers to use a template class for this purpose. There is nothing wrong with it, but I would prefer implementing using non-member template functions. <span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Chapter 8 describes how to write the <em><strong>startup<\/strong><\/em> code that runs after the hardware is reset, but before <em><strong>main<\/strong><\/em> gets control. This is a non-trivial task and the author shows how to do this in C++ and partly in assembly. Along the way, he shares interesting insights on the <em><strong>linker definition file<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>I personally found Chapter 9 interesting. There is some good discussion about writing low-level drivers in C++ with many examples.<\/p>\n<p>Chapter 10 discusses custom memory management. Dynamic memory management can be risky\/challenging in microcontroller programming because of limited memory constraints. In this chapter, the author shows how to overload <em><strong>new<\/strong><\/em> and <em><strong>delete<\/strong><\/em> operators to take control over dynamic memory management. In the last section of the chapter, there is a brief note on using exception handling to recover from memory errors, and the author correctly observes that this has to be done with care because of the overhead involved.<\/p>\n<p>Chapter 11 is on multitasking in C++. It begins with an overview of task scheduling and concludes with a mention of the C++ Threading library. <span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>In chapters 12 to 15, the author discusses various topics such as fixed-point and floating-point arithmetic, implementing digital filters, and some utility classes that are useful in embedded programming.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Chapter 16 is about simple extensions to the STL and replacements when the target environment does not provide the required functionality.<\/p>\n<p>Chapter 17 talks about using C code in C++, a fairly common scenario because a lot of useful embedded code is still written in C.<\/p>\n<p>Appendix A is titled <em><strong>A Tutorial for Real-Time C++<\/strong><\/em>. It is just a summary of C++17 features with no mention of anything remotely connected to real-time. Even Appendix B (<em><strong>A Robust Real-Time C++ Environment<\/strong><\/em>) has only a few paragraphs on interrupts and timing. The rest of it is pretty general stuff.<\/p>\n<p>Read this book if you want to get an overview of embedded programming for microcontrolers in C++. However, be prepared to be bombarded with C++17 features throughout! If your focus is Real-time programming in C++, then this book might disappoint you. I would have really enjoyed the book if the author had given a balanced perspective of C++17 features &#8211; what to use and when, and more importantly what not to use.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Title: Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming Author: Christopher Kormanyos Publisher: Springer-Verlag Year: 2018 (Third Edition) It was the title of this book which caught my attention a few weeks ago and I decided to invest in it. I am not in to real-time software development these days, but I always welcome material [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[94,49],"tags":[118,177],"class_list":["post-1339","post","type-post","status-publish","format-standard","hentry","category-book-review","category-c","tag-c17","tag-embedded-prgramming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-lB","jetpack-related-posts":[{"id":1278,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/02\/book-review-functional-programming-in-c\/","url_meta":{"origin":1339,"position":0},"title":"Book Review: Functional Programming in C++","author":"admin","date":"December 2, 2018","format":false,"excerpt":"Title: Functional Programming in C++: How to improve your C++ programs using functional techniques Author: Ivan Cukic Publisher: Manning Publications Co. Year: 2019 This book came out recently, about a week ago. I bought it immediately, and when I started to read it, I couldn\u2019t put it down! Very informative\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1496,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/03\/10\/book-review-c-concurrency-in-action\/","url_meta":{"origin":1339,"position":1},"title":"Book Review: C++ Concurrency in Action","author":"admin","date":"March 10, 2019","format":false,"excerpt":"Title: C++ Concurrency in Action Author: Anthony Williams Publisher: Manning Publications Co. Year: 2019 (Second Edition) \u00a0 The first edition of this book came out in the year 2012 and covered the concurrency features of C++ 11. Much has happened since then. The present C++17 is significantly richer in terms\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2868,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/11\/book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code\/","url_meta":{"origin":1339,"position":2},"title":"Book Review &#8211;  Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code","author":"admin","date":"July 11, 2022","format":false,"excerpt":"Title: Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code Authors: J.Guy Davidson, Kate Gregory Publisher:\u00a0 Pearson Education Year: 2022 My earliest introduction to C++ guidelines was through Scott Meyers\u2019 excellent book Effective C++ that first appeared in 1992. After programming in C++ for around 3 years\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2-233x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2986,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/01\/11\/book-review-adventures-in-rule-based-programming-a-clips-tutorial\/","url_meta":{"origin":1339,"position":3},"title":"Book Review: Adventures in Rule-Based Programming &#8211; A CLIPS Tutorial","author":"admin","date":"January 11, 2023","format":false,"excerpt":"Title: Adventures in Rule-Based Programming - A CLIPS Tutorial Author: Gary Riley Publisher: Secret Society Software, LLC Year: 2022 In an earlier article, I had talked about the relevance of Rule-based systems today. In that article I had also listed a few Rule engines that are popular and widely used.\u2026","rel":"","context":"In &quot;Knowledge Representation&quot;","block_context":{"text":"Knowledge Representation","link":"https:\/\/www.rangakrish.com\/index.php\/category\/knowledge-representation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover-188x300.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":980,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/07\/08\/book-review-the-modern-c-challenge\/","url_meta":{"origin":1339,"position":4},"title":"Book Review &#8211; The Modern C++ Challenge","author":"admin","date":"July 8, 2018","format":false,"excerpt":"Title: The Modern C++ Challenge Author: Marius Bancilla Publisher: Packt Publishing Year: May 2018\u00a0 This week I have been going through a new book titled The Modern C++ Challenge written by Marius Bancilla. The book is a collection of programming problems (along with suggested solutions) targeting C++ . The title\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2915,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/09\/18\/book-review-embracing-modern-c-safely\/","url_meta":{"origin":1339,"position":5},"title":"Book Review: Embracing Modern C++ Safely","author":"admin","date":"September 18, 2022","format":false,"excerpt":"Title: Embracing Modern C++ Safely Authors: John Laos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith Publisher: Pearson Education, Inc. Year: 2022 C++ is a complex language. Fortunately, we have several good books (and other online material) for programmers at various levels. A few weeks ago, I had reviewed and recommended\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/09\/Book2-235x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=1339"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1339\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}