Thought Leadership

Why move to C++?

As I am on vacation this week, I thought that I would leave behind a short note, which might provoke some discussion.

The most widely used programming language for embedded systems continues to be C. I observe great interest in the use of C++ and have frequently written and talked about the subject. Its adoption is also progressing steadily, though much more slowly than anticipated a decade ago. With this in mind, I would like to pose two key questions:

Why would you move to C++?

  • Is it because you want to use object oriented coding techniques?
  • Do you just want a “better C”?
  • Do you want to be able to leverage class libraries?
  • Do you think that the language results in more manageable code for larger projects?
  • Do you just want to be up to date?
  • Or something else …

Why would you not want to move to C++?

  • Is it because you are just happy enough with C?
  • Have you hear too many horror stories?
  • Are you worried about resource [memory] utilization?
  • Are you concerned about legacy code?
  • Or something else …

I would be pleased to receive any input via email or comment. Thanks.

Colin Walls

I have over thirty years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles and two books on embedded software, I am a member of the marketing team of the Mentor Graphics Embedded Systems Division, and am based in the UK. Away from work, I have a wide range of interests including photography and trying to point my two daughters in the right direction in life. Learn more about Colin, including his go-to karaoke song and the best parts of being British: http://go.mentor.com/3_acv

More from this author

Comments

0 thoughts about “Why move to C++?
  • I use C++ on embedded systems for greater flexibility in programming and especially for the safety features it enables like RAII, which virtually eliminate memory and other resource leaks. Add to that encapsulation and data hiding (possible in C, easier in C++), object-oriented techniques, and generic programming (omitted from your list but quite handy for optimizing for speed), and you’ve got some good reasons to consider it.

    Let’s not be Procrustean — C++ isn’t right for every project, but it’s worth consideration for most substantial ones. After all “embedded” is a broad category, ranging from a simple sprinkler system to a smart phone to a multiprocessor single board computer running Windows 7 or full-up Linux.

  • A few of the reasons I picked up an old C++ book, sat down, and learned the fundamentals are:

    1. My curiosity about this brave new world called “object oriented programming”, having seen bits and pieces of it here and there
    2. It is listed in quite a few job descriptions! I can’t tell you how many times a good familiarity with C++ was a requirement, even for what would be otherwise mild embedded systems jobs
    3. It allows another way of looking at problems (say for example encapulation, mentioned by Matthew) and hence

    Unfortunately unless I’m moving to more sophisticated platforms I won’t have the opportunity to use it much (due to limited compiler support for lots of popular devices).

  • I should have noted that interestingly enough, one compiler actually supports C++ for midrange 8-bit Microchip PICs (PIC16, PIC18F, etc.)

    That is SourceBoost C++. I thought that was interesting!

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/embedded-software/2011/03/14/why-move-to-c/