DEV Community

Discussion on: Pushing myself to C++

Collapse
 
bosley profile image
Bosley

Abstractions for peripherals on micro controllers is wonderful! I work somewhere that we have to target multiple micros and desktops with the same code-base and we leverage C++ for this constantly. While there are times that this bites us in a way that C wouldn't, we really gain a lot. One thing I find particularly useful is using inheritance and leveraging virtual functions for interfaces to abstract different types of IO. For instance, you could create a 'Writeable' or a 'Readable' interface that abstracts something for the application that will change depending on the target. On a micro you might be getting a discrete signal to trigger behavior, while in the desktop build it might be over a socket, or from a button.

There are other ways to handle the example I mentioned, but I think it it shows how useful C++ can be.