Why C++ is a viable alternative to C in embedded systems design

Fergus Bolger

November 18, 2008

Fergus BolgerNovember 18, 2008

So you're an embedded developer. You know that C is the right language for the job, although sometimes those maintenance cycles can be, well repetitive. You sometimes get that nagging feeling that you are coding like an automaton, repeatedly creating basic iterations over structures that are remarkably similar to ones from last week or last month.

You've heard the sales pitch for C++ as a powerful language but you also hear of horror stories about its large footprint, which makes it a no-go for embedded applications. Besides, it's so complicated: it must be really difficult to work with.

Does this have a familiar ring to it? The embedded development market covers a large range of application areas, including automotive, medical, defense and telecommunications. While C undoubtedly enjoys a good reputation as a strong and powerful language for embedded development, C++ does not have quite such a broad appeal. With today's capable and sophisticated C++ environments this is often an incorrect belief.

Why is C++ a viable alternative to C? As a language, it did of course grow from roots in C. Simply re-compiling a C project using a C++ compiler will yield more rigorous code type checking (there are some declaration incompatibilities that you may have to overcome first).

Once you embrace its core features, C++ offers a greater abstraction of data, which is an important objective for larger, more complex software systems. Object Orientation (OO) takes this abstraction a step further, where you can replace global "worker" functions with class functionality.

Templates are perhaps the biggest fear-factor against C++ usage, and most often quoted as the reason or presumption for large code-bloat experiences. But, in fact, well-designed template code offers elegant means of handling a variety of data-types consistently. C++'s Standard Library is an advertisement for such generic programming styles.

Exception handling is another area that suffers from FUD (Fear, Uncertainty, and Doubt). Exceptions in many C software systems will typically be a manual, programmatic task. This exception handling machinery can be replaced, albeit at a cost, with a more elegant C++ exception-based solution.

As always, the elegant solution only gets its due recognition when requirement changes are thrust on a development team. The speed with which well-crafted object-based designs can adapt in such circumstances is due, in part, to better abstraction and hiding of implementation.

< Previous
Page 1 of 3
Next >

Loading comments...