C++

last modified: October 23, 2025

Extreme Integers – Doom from Below

Posted on 2022-09-04— C++, Improve your Code, Learn

I take you on a short, pragmatic journey into C++ integer pitfalls—why signed and unsigned types behave oddly, how literals, negation and overflow can bite, and simple tests to reveal compiler quirks. If you work in embedded or systems code, please read the full post for examples and guidance.

Read this post

Event-Based Firmware Example

Posted on 2019-08-05— C++, Improve your Code, Learn

I provide a complete event-loop firmware example for SAM‑D boards (Arduino Zero, Feather M0). I explain module design—Buttons, Display, and a support library—initialisation and polling logic, and link the source and demo. If you're curious, read the full post for code and implementation notes.

Read this post

Consistent Error Handling

Posted on 2019-08-01— C++, Improve your Code, Learn

I walk through practical techniques I use to make firmware error handling clearer and more consistent in modern C++. From enum classes and a shared SimpleStatus to StatusResult templates and helpers like isSuccessful, I present readable patterns and code examples you can adopt. Read the full post for details and examples.

Read this post

Use Enum with More Class!

Posted on 2019-07-29— C++, Improve your Code, Learn

I explain C++11 enum class: why it prevents name conflicts, how it compares to traditional enums and common workarounds, with practical Arduino-friendly examples. If you want clearer, safer enum usage in your interfaces, read the full post for code samples and simple best-practice guidance.

Read this post

C++ Templates for Embedded Code (Part 2)

Posted on 2019-07-27— C++, Improve your Code, Learn

I continue exploring C++ templates for embedded systems, showing template classes, pin abstraction, and combining Sender and Pin examples to reduce firmware size and improve code clarity. I explain static methods, type aliases, and trade-offs between runtime flexibility and efficiency. Read the full post to see code and assembly comparisons.

Read this post

Bit Manipulation using Templates

Posted on 2019-07-23— C++, Improve your Code, Learn

I explore replacing unsafe bit macros with lightweight C++ templates to make embedded bit operations safer and clearer. I show templates for one-bit extraction, set/clear helpers, and compiled firmware size for Arduino Uno. Read the full post to see examples, exercises, and practical benefits.

Read this post

C++ Templates for Embedded Code

Posted on 2019-07-20— C++, Improve your Code, Learn

I walk through C++ templates for embedded projects, showing how function templates work, why they’re type-safe, and how they can keep firmware small and fast. Using Arduino examples like circularShift, reverseBits and a template-based Sender, I invite you to read the full post to learn practical tips and patterns.

Read this post

Auto and Structured Binding

Posted on 2019-07-16— C++, Improve your Code, Learn

I introduce C++17 structured binding with approachable examples: returning multiple values via std::tuple, binding to structs and arrays, and using references to avoid copies. If you use a C++17-capable compiler and want cleaner, clearer code, read the full article for practical examples and tips.

Read this post

Guide to Modular Firmware

Posted on 2019-07-14— C++, Improve your Code, Learn

I wrote a concise guide for embedded developers to refactor Arduino/C++ firmware into clean, modular components. I walk you through creating Display, Buttons, and Animation modules, testing and committing small changes, and improving maintainability. If you'd like practical steps and examples, please read the full article.

Read this post

It's Time to Use #pragma once

Posted on 2019-07-13— C++, Improve your Code, Learn

I explain why I prefer #pragma once over macro header guards and how it prevents subtle build errors and wasted debugging time. I’ll show examples, common pitfalls, and practical steps to replace guards in existing projects — read on if you want a simple, low-risk improvement.

Read this post

Write Less Code using the "auto" Keyword

Posted on 2019-07-12— C++, Improve your Code, Learn

I walk through practical ways I use C++11's auto keyword to reduce repetitive declarations, simplify range-based for loops, lambdas and register access, and make Arduino and embedded code easier to refactor. Read the full post for examples and tips you can apply to your projects.

Read this post

Units of Measurements for Safe C++ Variables

Posted on 2019-07-11— C++, Improve your Code, Learn

I show how I avoid unit mistakes in C++ by creating a templated Duration type and user-defined literals like 100_ms. I explain declaring Seconds/Milliseconds/Nanoseconds, adding conversions, and how the compiler catches unit mismatches with no runtime cost. Read the full article for code examples and the GitHub repo.

Read this post

Real Time Counter and Integer Overflow

Posted on 2019-07-10— C++, Improve your Code, Learn

I walk you through how real-time counters work, why integer overflow is usually harmless when you treat time as relative, and practical, Arduino-ready comparisons and code examples to avoid timing mistakes. If you want concrete patterns and simple tests, read the full post.

Read this post

Class or Module for Singletons?

Posted on 2019-07-09— C++, Improve your Code, Learn

I compare implementing a singleton as a class or as a module/namespace for Arduino firmware using simple LED driver examples and compiler measurements. I cover size, initialization and runtime trade-offs and explain when each approach makes sense. Read the full post for code, disassembly and practical recommendations.

Read this post

Event-Based Firmware (Part 2/2)

Posted on 2019-07-08— C++, Improve your Code, Learn

I guide you through evolving a simple Arduino blink example into a reusable event system. In Part 2 I cover function-pointer events, an EventLoop module, and practical multi-event examples. If you want cleaner, non-blocking firmware structure, read the full post for code and explanations.

Read this post

Event-based Firmware (Part 1/2)

Posted on 2019-07-05— C++, Improve your Code, Learn

I walk through a practical, minimal event-based approach to firmware using Arduino examples. Step by step I refactor blink sketches into modular events, introduce a millisecond timer, prevent skipped events, and encapsulate logic into classes and modules. Read on to follow the examples and apply them to your projects.

Read this post

How to Deal with Badly Written Code

Posted on 2018-08-31— C++, How and Why, Improve your Code

I often encounter poorly written C++ libraries, especially around hardware. In this post I outline four practical strategies—rewrite, refactor, wrap the library, or wrap the interface—to regain control, improve reliability, and reduce pain. Read on for pragmatic steps and examples you can apply to your projects.

Read this post

Make your Code Safe and Readable with Flags

Posted on 2018-05-06— C++, Improve your Code

I show how a small C++ flags template makes embedded register bitmasks safer and much easier to read. I'll explain why macros and CMSIS-style definitions lead to errors, and walk through clear C++11 examples and a simple driver. Read on to see the implementation and usage.

Read this post

How and Why to use Namespaces

Posted on 2014-10-31— C++, How and Why

I explain how C++ namespaces prevent name conflicts and why they matter, especially in Arduino projects. I walk through practical patterns—prefixing, selective using-declarations, and importing a namespace—with class and global examples. Read the full post for simple, pragmatic examples to keep your code clearer and conflict-free.

Read this post