Embedded C++ Basics Training and the MISRA C++ 2023 Guidelines

Embedded C++ Kurs

Embedded C++ Basics Training

This hands-on in-house course is aimed at developers in companies planning to migrate from C or older C++ standards to C++17 and learn about the latest tools and best practices.

Together with the Embedded C++ advanced course, this basic course covers all topics that are important for programming embedded applications with C++.

Embedded programs are often characterized by special requirements. They often have a special program structure (setup, loop), no heap may be used to avoid memory fragmentation, they are interrupt driven, have to comply with requirements such as the MISRA guidelines, etc.

Traditionally, embedded programs are often written in C. With the advancement of compilers, most C++ features today no longer have any disadvantage over C in terms of code size and speed.

  • The new C++ standards (C++11C++14C++17) have introduced new features that lead to faster and more compact code than the C alternatives.
  • One of the most important arguments in favor of C++, however, is that embedded programs are becoming more and more complex and larger. This complexity is often difficult to manage with C tools. Here, C++ offers enormous advantages that save development costs and contribute to the reliability of the applications
  • Most development environments for embedded programs (STM32CubeIDE, Espressif IDE, etc.) now support C++17.
  • The MISRA guidelines, which used to be primarily C-oriented, also point out the advantages of C++: „… now C++ is in the position once held by „C“;“
  • The MISRA C++ 2023 Guidelines for safety-related systems and the C++ Core Guidelines are presented together with the language elements. Compliance with these best practices is often recommended or required to obtain safe, maintainable and efficient C++ code.
  • In addition, an outlook is given on the most important enhancements in C++20 and C++23, which will soon be available in the next gcc toolchains.

Course Objectives

In this Embedded C++ basic training, fundamental C++ elements and concepts (e.g. types, statements, object-oriented programming) are introduced. The focus is on the new language features of C++11C++14 and C++17 and their use in embedded systems. Numerous examples show how they can be used with common microcontroller boards (STM32ESP32Raspberry Pi etc.).

Target audience

This course is aimed at

  • experienced developers who want to write embedded applications using state-of-the-art C++17. It is also aimed at
  • decision-makers and technology managers, project leaders, etc., who want to evaluate how C++17 can optimize their teams‘ development processes.

It is often delivered as an in-house seminar so that companies can bring their teams up to date together.

Typical application fields:

  • Automotive and aerospace: developers who have to meet high safety and reliability requirements.
  • Industrial automation: programmers of complex control and monitoring systems.
  • IoT and smart devices: developers working on modern IoT devices where memory and performance optimizations are crucial.
  • Medical technology: engineers developing safety-critical and resource-efficient software for medical devices.

Prerequisites: good knowledge of C.

Contents

The contents can be adapted to the wishes of the participants.

1. Embedded Systems

  • Embedded application fields
  • Special requirements for embedded applications
  • Overview: C and C++ in comparison
  • ESP32 and STM32 boards

2. Fundamental Types and Statements

2.1 Integral and floating point types

  • Fixed-width integral types
  • Separators for number literals, binary literals
  • Implicit type deduction with auto
  • Type safe initializations with initializer lists
  • Bit operations

2.2 Control structures and functions

  • Conditional statements and loops
  • Initializations in for/if/switch
  • Functions
  • Interrupts and interrupt service routines (ISR)
  • Value and reference parameters
  • Using C and C++ libraries, namespaces
  • Default arguments
  • Function pointers, Interrupts and Interrupt Service Routines (ISR)
  • The „function type“ std::function

2.3 Constants

  • Runtime constants with const
  • Compile time constants with constexpr
  • constexpr functions
  • static_assert and unit tests at compile time

2.4 Overloaded functions and operators

  • Overloaded operators with global operator functions
  • Finding memory leaks with overloaded new and delete operators
  • User-defined literals

2.5 Enumeration types

  • Weakly typed enumeration types (C/C++03)
  • enum constants and conversions
  • Strongly typed enumeration types (C++11)
  • State machines and Task scheduling

2.6 Attributes

2.7 Modules (C++20)

  • Using the standard library as a module
  • Defining modules

3. The string classes string, wstring etc.

  • Member functions for string manipulation
  • Raw string literals
  • C++11 string conversion functions to_string, stoi etc.
  • C++17 string conversion functions: to_chars and from_chars
  • string_view – Strings for viewing
  • C++20: std::format

4. Arrays and containers

  • C-style arrays
  • C++ arrays: std::array
  • Dynamic Arrays with std::vector
  • Advantages of std::array and std::vector over C-style arrays

5. Pointers and Smart Pointers

  • Dynamic memory management
  • The nullptr literal
  • Pointer conversions
  • Smart pointers: shared_ptr, unique_ptr and weak_ptr

6. Object-oriented programming

6.1 Classes, data members and member functions

  • Data Encapsulation with private and public
  • Constructors and Destructors
  • Classes without Pointers, RAII and the Rule of Zero
  • Initialization Lists as Parameters, for Arguments and Return Values
  • The Default Constructor
  • Member Initializers
  • Overloaded Operators with Member Functions
  • The Copy Constructor and the Assignment Operator
  • Explicitly deleted and defaulted functions with =delete and =default
  • Converting and explicit constructors
  • Static class members
  • inline variables, especially static inline data members
  • Constant objects and member functions

6.2 Inheritance and Composition

  • Conversions between public derived classes
  • Hidden elements
  • Multiple inheritance
  • Virtual functions, late binding and polymorphism
  • Virtual functions with override in C++11
  • Pure virtual functions and abstract base classes
  • Interfaces and multiple inheritance

6.3 R-value references and move semantics

  • Move semantics in the C++ standard library
  • Move semantics for Rule of Zero classes
  • Move semantics for custom classes

About „Embedded C++ Basics Training“

Teaching style of the C++ seminar

Lecture with many examples. A balanced combination of theory and practice.

  • At the beginning of a new topic, an overview of applications, basic ideas and syntax is given.
  • The concepts and the syntax are illustrated by using carefully selected and proven examples. Often, best practices“ are presented.
  • The manuscript contains numerous practical exercises.
  • If desired, tasks from the work of the students can also be dealt with. This should be arranged before the start of the training.

Training Materials

Extensive and detailed training materials (approx. 200 pages) – Full text, no PowerPoint slides containing only keywords. Therefore, the course materials can also be used as a reference at work.

Place and time of this C++ training

This seminar is offered as an inhouse seminar (at your site). The implementation as a face-to-face seminar is preferred, but is also possible as an online seminar. Dates by arrangement.

Duration: 4-5 days (depending on prior knowledge)

Lecturer

Prof. Richard Kaiser has been conducting seminars for companies for many years, mainly on software development and the programming languages C#, C++ and C. He knows the requirements of practice and addresses them in detail, both in the basic concepts and in the details. His clients include renowned global corporations and small and medium-sized enterprises. He is the author of several books on C++, most recently „C++ mit Visual Studio 2019“. He was a member of the DIN standardization committee Information Technology NI-22 for many years.

Contact Prof. Richard Kaiser