|
|
|
|
|
by theICEBeardk
95 days ago
|
|
While this is helpful in a way this blog also contains outdated information. Given that in embedded you most of the time build the world and have most of your stuff as source code you should never get stuck on an old compiler unless it is a one-shot project. And that leads to the ability to use modern C++ methods in places where it is highly useful such as the ability to use "if constexpr" and templates to make your somewhat generic code optimal for a specific usage scenario like writing a templated driver that adapts to the specific hardware variant you are building. This means you can often run without making runtime decisions on hardware situations that cannot ever occur because the specific chip or board does not even have the option. Also I noticed the virtual interface mentioned and I would express a minor point of caution there for embedded developers. A virtual interface is really meant for dynamic/runtime situations where the object behind the interface can change at runtime. In embedded that is a more rare case. Consider using concepts to define such interfaces and pass the concrete objects as template parameters where it makes sense. I have on several occasions these last four years reduced the binary size overhead of products by doing this as an object accessed through a virtual interface prevents the removal of unused methods from the final binary (they have to be present even with devirtualization happening to reduce the indirection cost). Also template bloat is real but also a somewhat over-"hyped" problem in embedded. It occurs when the same template is run several times to produce many variations of the same template. In most template programs this will not happen by accident. Mainly avoid making any reoccuring template configuration apart of the type. Instead we now have the option of initializing objects during compile time using constexpr objects. Make your configuration of the object that way (maybe even consteval) and use that in "if constexpr" if possible. All compilers relevant in embedded can manage to put this configuration into the read-only/flash memory and load it in during start-up/boot. |
|