C++ For Embedded Developers (2023-03-20 - 2023-03-23)¶
Goal¶
Give an idea how an experienced C programmer can benefit from the C++ toolcase. The following aspects are covered, accompanied with many exercises.
C++ is an object oriented language. That term alone has many facets, and a solid understanding of each is given. Constructors, destructors, automatic pointer/base-class conversion, late binding (“abstract”?), and all that.
C++ also brings a rich toolset in form of its standard library. After a short conceptual introduction, containers and algorithms are something that is immediately useful for non-OO programmers.
C++ does not stop there; starting from its 2011 definition, the language has undergone a major revolution. An overview is given.
Work Environment¶
Preferred: Ubuntu under Windows (WSL)¶
I suggest you use the Windows Subsystem For Linux (WSL2) (Microsoft documentation here). This sets up a virtualized Ubuntu inside Windows, together with all interoperability wazoo.
When installed, open a Ubuntu terminal, and install the software that is required for this training.
$ sudo apt update
$ sudo apt install git build-essential cmake libgtest-dev libgmock-dev
Unsupported Environments¶
It is also possible to setup a Linux-like environment on native Windows, using the following emulation layers:
You may use these, but be warned that there might not exist enough trainer-side knowledge to help you out if anything goes wrong.
Skeleton Project Setup¶
Follow the instructions in the course project README to setup the initial version of the course project.
Day 1¶
Classes, Objects, Methods¶
From Data Encapsulation
Exercises¶
Miscellaneous¶
One Definition Rule (ODR), and
static inline
class members: static Member Variablesconstexpr
explored. How is it used to populate therodata
section and save RAM?Sample code: rodata.cpp
Global objects from different compilation units are initialized in unspecified order. See here.
Day 2¶
Heavy Weight OO 💪¶
Resource Management Pitfalls¶
Exploring object copy when resources have to be explicitly managed: Object Copy (And Resource Management): There Be Dragons
Day 3¶
R-Value References/Moving, And Managed Pointers¶
A Little Concurrency¶
Only if there is time (and fun): have a look at Multithreading
Exercise¶
Based upon an object oriented encapsulation for OS primitives (timers and GPIOs, mainly),
Sensors
A sensor abstract base class - an interface
A number of concrete sensor implementations
A configured set of those, measuring live data
Live data is posted via another interface
Display(s)
Another interface in the system
Display measurement values
Concrete implementation: a software PWM using a timer and a GPIO (as opposed to hardware PWM
Untold So Far¶
C++ Standard Library¶
Pointer Arithmetic Recap: Pointers and Arrays
Basic Algorithms
Sorted Array Algorithms
Sequential Containers
Associative Containers