In C++ it's common to stream data. You write to a file using the << operator.
example:
cout << "hello, world! << endl;
In this blog I'm making my own minimal output stream class. Just enough code to show that it works. This co...
C++ has a range loop. A for loop that will run over all elements in the range you give it:
std::vector<int> v = {0, 1, 2, 3, 4, 5};
// ...
for (auto i : v)
std::cout << i << ' ';
std::cout << '\n&#...
Context: A Practical Project
Over the past days, I have been developing a Python Qt application to generate weekly meal plans for my baby and family.The project itself is not overly complex, but it has provided a valuable opportunity to reflect on so...
In object oriented designs, there are times when you replace an object by another. Example: when you store an object into an STL container. In a lot of those cases, you create an object, and add it. The object in the container is a cop...
You may read guidelines that say: "never use an object as return value of a function. Because of performance reasons". Because the object is copied into the receiving variable when returning from the function call. That was true in C++...
task: Let's say that you are writing a C++ class, where the objects have to be sorted or compared.
In classic C++, you 'd write an operator overload for <, <=, == , !=, >= and >. In modern C++, you can get all that fun...
If you're interested to try out the latest C++26 options: The Windows port for GCC 15.1 is available for download.I installed GCC 15.1.0 (with POSIX threads) + MinGW-w64 13.0.0 UCRT - release 2. To install, download the zip file, ...
For an embedded design, I made a featherweight class. A C++ construct that used no more data or code size than a traditional C design.
class command {
public:
inline command(uint32_t steps, bool reverse) : cmd_(steps << 1 |...
CMake has an easy way to get access to libraries headers and source: target_link_libraries(your_lib, some_lib). Where your_lib is the library you are developing, and some_lib is a library you depend on. Ideal if you are using a library, and...
*tiny like in: 0 bits of data, 0 code instructions added, 0 clock ticks
scenario: you have a resource that needs to be initialised before use, and deactivated when done. We usually do that by calling some code before the actions, and some code after ...
This blog is based on real world work. I'm controlling a TI DRV8711 stepper motor controller via SPI.
I need to modify 16-bit registers of that IC. TI provided a header file with register definitions, and code to convert that struct to a 16 bit ...
In C++, templates allow you to write generic code, that can handle many types. But almost always, there will be types you can't handle.
In my case, I have a callback manager that supports functions that return a void, a number, a bool or a class...
This is a "classic C++" post, something that's been part of the language since conception: How to use an operator in your class design.
I developed a callback class. Your "gizmo that needs to callback something" would hold an instance of that class (...
When you work on a project, you often rely on external libraries and source code. If you use CMake as your build tool: it can download the artifacts for you. And make them available during build. By using FetchContent.
use case: your pro...
I'm experimenting with new C++ constructs. GCC 15 implements an interesting concept of the C++26 standard: A function can return a status, and either a value or an error message. In a previous post I tested one of C++ standard function...
I'm experimenting with new C++ constructs. GCC 15 implements an interesting concept of the C++26 standard: A function can return a status, and either a value or an error message.Example is the standard std::to_chars() function. It...
I'm experimenting with new C++ constructs.
In C++ callbacks and templates , I developed a generic object oriented callback handler using templates.In modern C++ modules I tried out an example that uses C++ modules...
Since C++20, a new feature is available: modules.
We're all used to C++ header and source files. And we all know their pros and cons. Because I'm reviewing a new C++ alternative for them, I'll focus on the cons of header files:
header file...
When writing reusable code, I like to be consistent and use standards. For C++, there are many flavours out there.
I've been looking around for guidance on writing modern C++ code, with templates. That's when I bumped into the µOS naming s...
The C++ Standard Template Library has a decent set of containers. std::array, std::vector, std::list, ...
When you write a software function, it can be useful to handle whatever container the user wishes to use.
In my little print function here...
I wrote a series of articles about GitHub Actions. To:
validate that no one submits code that breaks the build
automate nightly deploy and update online documentation
The flow below shows the current setup. Read it down to up, to understand wh...
I have a Raspberry Pico GPS library project. It comes with several examples. And each example can communicate to the GPS over I2C or UART.
Initially, it was a single-example project. I used a definition in the CMake config, that allow...