This repository contains the code examples for C++ in Embedded Systems: A Practical Transition from C to Modern C++, published by Packt.
The book is aimed at embedded developers moving from C to modern C++, with a practical focus on using C++ effectively in resource-constrained embedded systems.
docker pull mahmutbegovic/cpp_in_embedded_systems:latest
docker run -d -it --name dev_env mahmutbegovic/cpp_in_embedded_systems
docker exec -it dev_env /bin/bash
| Chapter | Title |
|---|---|
| Chapter 1 | Debunking Common Myths about C++ |
| Chapter 2 | Challenges in Embedded Systems with Limited Resources |
| Chapter 3 | Embedded C++ Ecosystem |
| Chapter 4 | Setting Up the Development Environment for a C++ Embedded Project |
| Chapter 5 | Classes – Building Blocks of C++ Applications |
| Chapter 6 | Beyond Classes – Fundamental C++ Concepts |
| Chapter 7 | Strengthening Firmware – Practical C++ Error Handling Methods |
| Chapter 8 | Building Generic and Reusable Code with Templates |
| Chapter 9 | Improving Type-Safety with Strong Types |
| Chapter 10 | Writing Expressive Code with Lambdas |
| Chapter 11 | Compile-Time Computation |
| Chapter 12 | Writing C++ HAL |
| Chapter 13 | Working with C Libraries |
| Chapter 14 | Enhancing Super-Loop with Sequencer |
| Chapter 15 | Practical Patterns – Building a Temperature Publisher |
| Chapter 16 | Designing Scalable Finite State Machines |
| Chapter 17 | Libraries and Frameworks |
| Chapter 18 | Cross-Platform Development |
The code in this repository is maintained and may differ slightly from the listings printed in the book. Notable changes (August 2026):
- All examples were formatted with clang-format using the configuration shipped in this repository, so brace placement and indentation can differ from the printed listings.
- Chapter 9,
main_strong_types.cpp: getters return values instead of mutable references, narrowing conversions are explicitstatic_casts, and the_msliteral asserts its range — the example now fully practices what the chapter preaches. - Chapters 11–17,
signal.hpp: the element type is checked to be floating-point, step computation uses the element type instead offloat, and the default constructor zero-initializes the array. - Chapters 11–17,
units.hpp: the unit class isconstexpr, the literal operators moved into the header (units.cppwas removed),get_miliwas renamed toget_milli, and dividing a voltage by a resistance now yields a typed current. - Chapter 14,
main_task.cppandmain_seq.cpp: thetestclass moved out ofmain()to file scope. C++20 allows a local class's static member function as a template argument and the GCC 13.2 in the Docker image accepts it, but GCC 12 and older reject it — the change keeps the examples building on older toolchains too.