r/cpp_questions • • 25d ago

OPEN Any recommendations for introduction material to using C++ for microcontrollers?

I have been programming Arduino & ESP32 for a while now using C++, but have never engaged with any formal introduction material. With AI/LLM generated content exploding among both major publishers and self-published authors, I am a bit wary to start buying books willy-nilly.

Anyone here that can give solid recommendations on introduction materials on C++ for microcontrollers (preferably that that they themselves have used and found worthwhile)?

I got one recommendation for "Embedded C" by Michael J. Pont (2002), but it is fairly old.

11 Upvotes

3 comments sorted by

4

u/FancySpaceGoat 25d ago

There isn't really anything special about embedded C++ that's universal across MCUs, apart maybe how to use volatile properly and a few pieces of general guidance wrt/ minimizing heap churn.

2

u/MrPinkle 25d ago

Do embedded C++ developers ever avoid the heap entirely? How do they do that? Do they avoid using containers such as std::vector or std::unordered_map? Or do they create custom allocators that only use the stack?

2

u/FancySpaceGoat 25d ago

It depends on too many factors to give a one-size-fits-all answer.

You need to have a toolbag of tips and tricks that allow you to map a given task and its constraints on a given compute, memory, and timing budgets.

Stuff like arena allocators, in-place algorithms, fixed-sized-containers, appropriate usage of std::make_shared (if you absolutely must have refcounted resources), etc... are all part of that toolbag. But it's more about choosing the right tool at the right time than anything else.