Skip to content

Repository files navigation

Cpp-in-Embedded-Systems

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.

Install and run docker image

Pull the image

docker pull mahmutbegovic/cpp_in_embedded_systems:latest

Run the image

docker run -d -it --name dev_env mahmutbegovic/cpp_in_embedded_systems

Enter bash

docker exec -it dev_env /bin/bash

Chapters

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

Changes since publication

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 explicit static_casts, and the _ms literal 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 of float, and the default constructor zero-initializes the array.
  • Chapters 11–17, units.hpp: the unit class is constexpr, the literal operators moved into the header (units.cpp was removed), get_mili was renamed to get_milli, and dividing a voltage by a resistance now yields a typed current.
  • Chapter 14, main_task.cpp and main_seq.cpp: the test class moved out of main() 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.

About

C++ in Embedded Systems, published by Packt

Resources

Stars

104 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages