It's quite interesting to see that there are a lot of pros and cons when it comes to C++, so I though I would share a few things I use when developing in C++ for embedded (and more specifically ARM Cortex-M).
The important thing is to use libraries that solve real problems, not use things just for the sake of using it.
1. State Machine Language:
https://github.com/boost-experimental/smlSML is a DSL (domain specific language) where you specify a state machine, and it generates optimized code for it.
I am using it in all my current embedded projects as soon as I need a state machine, and it comes from 2 very important features:
- There is a tool to convert the code you write for the state machine to a block diagram. This has saved me a lot of times.
- I have tried and cannot beat the state machine generated in execution speed, amazingly fast.
Thanks to it being generated at compile time, extra knowledge can be embedded in the DSL with allows for optimizations the compiler cannot see.
And this is one of the things that really is useful in embedded, as we as embedded engineers have a lot of domain specific knowledge that we put to use.
In the case of Template Metaprogramming, almost all of this knowledge and optimizations can be embedded into the DSL being created.
2. CRECT (an event based scheduler computed at compile time):
https://github.com/korken89/crectI am authoring an RTOS (if you can call it that) which generates an Stack Resource Policy scheduler for your system at compile time.
After generating the connections between resources and jobs, the scheduler is mapped to the NVIC of the Cortex-M MCUs, making it extremely fast and efficient.
I would recommend the interested to check the README in the link.
CRECT uses a DSL to describe which jobs can take which resources, that in the allows it go guarantee deadlock and data race free execution (if not using resources outside the resource system).
I presented this system at the emBO++ conference in March (embedded C++ conference) however the video is not online yet sadly.
There I started a dare, if anyone could make a scheduler that is faster - as it uses the NVIC to make context switches manual code cannot beat it.
A pleasant side-effect is that it is very easy to get sleep into the system, as when all event have been handled one can sleep (there is no code in main).
3. Extra evening materialThere is a person call Odin Holmes which does a lot of talks on embedded and C++, and the systems being created.
I would really recommend people to watch his talks and get inspiration:
https://www.youtube.com/playlist?list=PL85B7uUiTlCFXO_XL_2x1tlr7B8Lg9NFpFor those who want to see the future of special function register abstraction can have a look at
kvasir::bit.