Safe and Efficient C++ for Embedded Environments


Course Description

In today’s tech landscape, recent advancements in C++ provide tools to tackle the unique challenges of embedded environments. This is true even for environments following MISRA, Autosar, or SIL guidelines.

This course will enhance your embedded systems skills using modern C++. By practical examples, you will learn how to write code that is safer, more robust, and more efficient. You will see patterns to replace the POSIX length value API.

We'll start with the basics and gradually move on to more advanced topics, all designed to make your code stronger and more efficient.

Coroutines add a whole new level to writing parsers. You'll learn how they work and how to use them without relying on the heap.

Many embedded systems operate without a heap. We explore standard compliant and undefined behavior-free ways to deal with custom allocators. You’ll see firsthand how unique_ptr, from the Standard Library (STL), can be a game changer even in memory-constrained environments.

This directly leads to the next topic, using the STL in an embedded environment, which often disallows using the global heap or exceptions. You’ll learn to effectively leverage STL features in these contexts. Do you need to use std::chrono but face compatibility issues with your hardware clock? I’ll show you how to seamlessly integrate your custom clock with STLs std::chrono, ensuring that everything works harmoniously.

Lastly, error handling can be tricky in embedded programming, especially without exceptions. You’ll gain insights into the powerful capabilities of C++23's std::expected, making your code more readable, maintainable, and resilient.

What participants will gain

By the end of this course, you'll not only be well-versed in the latest C++ features tailored for embedded systems but you'll also be equipped to write type-safe code that effectively avoids common pitfalls such as out-of-bounds access. Improve your code's readability and maintain efficiency, all while mastering the art of embedded programming with confidence.

Course Outline

  • Language features in C++
    • Explicit data type conversion
    • Uniform initialization
    • Digit separator
    • auto type deduction
    • range-based for loops
    • Strongly typed enum
    • static or inline
    • Attributes
    • User defined literals applied
  • Avoid code bloat in C++
  • Controlling your objects (OOP)
    • class or struct
    • explicit
    • Default member initialization
    • Constructor delegation
    • Deliberately disable member functions
    • Virtual functions
    • Curiously Recurring Template Pattern
  • ROM-ability
  • Coroutines: Resumable functions
  • Living without the heap
    • Dynamic memory management
    • Properly aligning your local heap buffer
    • Placement-new
    • The STL as an alternative to placement-new
    • Implementing a pool allocator
    • std::unique_ptr
  • Standard Template Library meets embedded
    • STL rules of thumb
    • Safe headers for embedded environments
    • std::chrono
    • std::array
    • std::span
    • std::optional
    • std::string_view
    • std::expected
    • Peaking into algorithms

Included in this course are

  • A handout as color PDF, which includes all references and an acronyms list;
  • The source code for the exercises as well as sample solutions for all exercises as a ZIP-file;
  • Certificate of attendance;
  • A complimentary copy one of my books