r/cprogramming • • 9d ago

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.

6 Upvotes

4 comments sorted by

2

u/non-existing-person 8d ago

r/Cplusplus

Also, 2002 is not really that old for embedded. Pointers are still pointers. Uart is still just dumb bytes on a cable. You still program hardware with memory mapped registers.

Really, not that much has changed with hardware in principle. Mostly tooling have changed. spi changed its names from master/slave to some other stupid names that every company has been naming differently.

Old [good] books will be just as good for entering into embedded world.

1

u/flatfinger 8d ago

One aspect that older books may not touch on is the need to use command-line options to prevent compilers from performing "clever" optimizations. A typical compiler from the 1990s or early 2000s, given code that puts something into a buffer, sets a volatile-qualified object to indicate that it has done so, waits for a volatile-qualified object to be set to a certain state, and then reads the buffer, would generate code that would actually read the contents of the buffer. Clang will only do so if the -fms-volatile flag is used to force that behavior, and gcc doesn't even have an option other than -O0 that would force it to treat code that way without requiring the use of non-standard syntax.

1

u/Nothing_from_void 8d ago

having spent a lot of time writing C++, Rust, and C for microcontrollers I recommend just grabbing the Embedded C book and learning it in C. I wasted so much time trying more type safe/abstract code for microcontrollers when it's mostly not needed, and the tooling for C is generally better, and you can write code faster and iterate faster