As a beginner or immediate C++ programmer, you heard never mixing unsigned and signed integer types or avoiding unsigned integers at all. There was also this talk about undefined behaviour. Yet, in embedded software development, there is no way around unsigned integers – so what is behind all these warnings? Wonderful that you strive to…
Category: C++
C++ is a wonderful programming language but not very beginner friendly. Learn how to use the language better and more professionally with the articles in this category.
Event-Based Firmware Example
If you read the previous articles about event-based firmware, modularisation and templates, you may wonder how to combine all these concepts in your firmware. I created a working firmware example, based on an event loop. In contrast to the minimal example code in my articles, this one contains everything you need to start a project….
Consistent Error Handling
Error handling in firmware is a difficult task. If you decide to ignore errors, the best you can expect is a deadlock, but you could also damage the hardware. When reviewing existing code, I often find boolean return values or a system of error codes. The problem with these systems is the lack of readability….
Use Enum with More Class!
You may be familiar with enum values, but do you know about enum classes? This great feature was introduced with C++11 to solve several problems with the regular enum declaration. Now I will explain the enum class declaration and demonstrate its practical uses. Although the examples I provide are intended for the Arduino Uno, the…
C++ Templates for Embedded Code (Part 2)
Templates are a powerful feature of the C++ language, but their syntax can be complex. Here I will continue with the second part of the article. Although the examples I provide are for the Arduino Uno and Adafruit Feather M0, the concepts will work with any platform and with all modern C++ compilers. Recap of…
Bit Manipulation using Templates
Did you read my article about C++ templates for embedded code? You learned how to use function templates. This post adds a practical example to this topic. Bit Manipulation You may be familiar with bit manipulation code like this: For simplicity, you like to select single bits using its index number. This is a common…
C++ Templates for Embedded Code
Templates are a powerful feature of the C++ language but their syntax can be complex. This causes some developers to not use them, while others are concerned that templates might cause bloat to the compiled code. I will explain how templates work and how you may use them in your code. Although the examples I…
Auto and Structured Binding
This article is just a short follow-up article for “Write Less Code using the ‘auto’ Keyword”. Structured binding is something handy, introduced in C++17. Therefore, only the latest compiler will support it. If you are mainly write embedded code, you may skip this article, because it will take some years until C++17 support is available…
Guide to Modular Firmware
This article is for embedded software developers with a solid working knowledge of C or C++, but who struggle with large and complex projects. If you learn to develop embedded code, e.g. using the Arduino IDE, you find plenty of small example programs. It is helpful to get things started quickly, but as soon as…
It’s Time to Use #pragma once
In my opinion, preprocessor macros and the outdated #include mechanism are one of the worst parts of the C++ language. It is not just these things are causing a lot of problems, even more, it is very time consuming to find them. This article will focus on #pragma once. In the past, I already wrote…