A thought about C++ for embedded systems

Some programmers say that C++ is a resource-killer when it’s used in an embedded system. Perhaps that’s true if one abuses or misuses some of the most powerful features this language offers.
However, C++ has a lot of features that the programmer can take advantage, even if he or she doesn’t want to use classes. C++ let us to write code in both paradigms, structured and object-oriented. So, if you want to drop away the object-oriented and stick to the structured one, you can still write more secure and very strong applications.

A descriptive, but not extensive for any means, list of useful features for embedded programming in C++ is:

  •  Stronger typing
  •  Templates, template specialization and template metaprogramming
  •  New type bool
  •  nullptr instead NULL
  •  References instead of pointers
  •  Function overloading
  •  Operator overloading
  •  Namespaces
  •  constexpr
  •  static_assert() feature
  •  Chainning methods: m0.().m1().m2()

Stronger typing is one of my favorites, because you are not allowed to send, say an integer, when a method is expecting an enum value. I was used to mix them, until I compiled a C application with a C++ compiler. It throws a lot of errors of that kind.

Does any of this features add extra overloading? Nop. Does it worth? Of course, Yes !!

Also, in C++ it’s discourage some misuses of the preprocessor, like define constants through #define(s). Instead one can use const or constexpr expressions. And much of the conditional compiling might be replaced with templates.

Besides the aforementioned C++ facilities, we can take advantage of the compiler’s warning system, which, if use correctly, will save us a lot of time and headaches.

Hope senior and junior programmers look at C++ for their incoming projects.

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s