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.

Preparing Recommendations

More Blog Posts

About Colin Walls

Colin WallsI have over twenty-five 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. Visit The Colin Walls Blog

Follow on Twitter

More Posts by Colin Walls

Preparing Recommendations

Comments (↓ Add Your Own)

6 Comments on this Post

Commented on 1:38 PM, Mar 30, 2011
By Matthew Limber

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.

Commented on 4:59 PM, Mar 30, 2011
By micro_engineer

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).

Commented on 8:41 AM, Mar 31, 2011
By Colin Walls

Absolutely. Where C++ fits, it can be a good choice. On a small system or a simple application, it is likely to be overkill, at best.

Commented on 8:44 AM, Mar 31, 2011
By Colin Walls

You are right Marty, C++ only makes sense if you have a reasonably high power [probably 32-bit] CPU and a sensible amount of memory.

Commented on 5:23 PM, Apr 8, 2011
By micro_engineer

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!

Commented on 10:16 AM, Apr 11, 2011
By Colin Walls

That does sound interesting. I'll have to look into it.

Add Your Comment

Please complete the following information to comment or sign in.

(Your email will not be published)

Archives

Tags

RSS