Many embedded projects still use older (and outdated) environments that don't allow developers to use a new C++ standard. This is a mistake. Not only do programmers miss out on the newly added features, but C++11 also fundamentally improved several aspects.
Since version 11, things have been happening again in the world of C++. While the further development of the standard was largely ignored by embedded developers for a long time, version 11 of C++ has given the programming language renewed momentum and a number of new features that are worth taking a closer look at.
One example that is often used is the new null pointer – nullptr.
Example:
void doSomething(char * pc) { cout << "char*" << endl; } void doSomething(int i) { cout << "int" << endl; }
Age Code:
void testNullPtr(void) { doSomething(NULL); doSomething(0); }
Both calls result in `doSomething(int i)`, even though the first version appears to have passed a pointer. The implicit type adjustments result in a conversion to an integer.
A cast is required for the correct call:
void testNullPtr(void) { doSomething(static_cast (NULL)); doSomething(0); }
It's different in C++ from version 11 onwards:
void testNullPtr(void) { doSomething(nullptr); doSomething(0); }
The "real" null pointer now tells the compiler what to do.
Elsewhere, greater emphasis was placed on safe programming. Type-safe enumerations (enums) and the new smart pointers are worth mentioning. The introduction of RValue references simplifies the handling of temporary objects.
Many small improvements make the developer's daily work easier.
This includes the automatic for loop (called a foreach loop in other programming languages) as well as the automatic type detection of variables. This was further improved in version 14 (especially regarding templates). Incidentally, if you're still using an older compiler, that's a good reason to skip version 11 and go straight to C++14.
Another noteworthy innovation is the Lambda functions, These functions operate flexibly and anonymously. They allow you to complete small tasks directly on-site without having to write an additional function. Furthermore, they are very useful when it comes to adjusting the parameters passed to function calls.
In addition to the language extensions, the standard library was also improved and expanded. Among other things, it now includes, for the first time... Classes for multithreading.
Even though many innovations of the C++ language are only of limited use for many embedded projects, the newer C++ versions bring so many improvements and simplifications to everyday development that switching is worthwhile.
Stay up to date – with MicroConsult training courses on C++ and C++11!

