-
A nice little defer helper class in C++
There are a bunch of cases where there is cleanup that needs to happen before a function finishes, regardless of the exit path. I’ve talked about how you can accomplish this in C with GNU extensions in the past. Today I want to talk about doing the same thing in C++ (hint: it’s a lot — read more
-
How to Handle Resource Cleanup in C Unit Tests
There’s an interesting design constraint I encountered fairly early on when writing a purely C-based unit testing framework that I hadn’t really thought much about when using testing frameworks in other languages like C++, C#, and Java. How do you design a testing framework where resources are cleaned up regardless of a test passing or — read more
-
An interesting bug
I was working on a string library in otter this weekend and ran into an interesting bug and I probably should have known better. The string structure uses a cool feature in C (as of C99… so recent!) called flexible array members. They allow an “empty” trailing array field in the struct that can be — read more
-
Automatic unit test discovery in C
Another thing that I’ve been working on in my project, otter, is a basic unit testing framework. There doesn’t seem to be a popular and standard unit testing framework in C, as far as I’m aware. It also didn’t feel right to write my source code in C and then using something like Google Test, — read more
-
Improving partial recompilation in my custom build system
As I’ve been using the basic build system I’ve created for otter, there were several annoyances that kept cropping up. The one I want to talk about today is determining when a C file has changed and, therefore, needs to be recompiled. For C (and C++), you can basically think of a single .c file — read more
-
Simple build system in C
I first started my current project, otter, with an interesting premise: can you have a C project that only requires the compiler to build itself? This means having a project that can bootstrap its own build system and then build the rest of itself without needing something like CMake, Meson, or Makefiles. Why do this — read more
-
Integrating terminal Emacs with the Wayland clipboard
I’ve recently been using Emacs in a terminal instead of its GTK frontend. This is mostly because the PGTK GUI for the version of Emacs (version 30.2… so the newest AFAIK) shipped in Fedora is abysmally slow when full-screened at 4K display resolution. This doesn’t seem to be the case with GNOME’s terminal (full-screened at — read more
-
Taking some inspiration from Zig allocators
Zig seems like a great language and has good ideas for how to improve on a systems level language without sacrificing compatibility with C. I haven’t used it in any projects, but I love reading about it whenever I come across it on Hacker News or the like. One of the design choices that I’ve — read more
-
A nice little nameof macro in C
There’s a great keyword in C# called nameof which is used to “stringify” a variable, type, or member. It is used all the time for simple things like checking if a variable is null at the beginning of a method. The nameof keyword is great. If the variable integers ever changes to something like integersToPrint, — read more
-
The “cleanup” attribute is pretty neat
I’ve been doing a lot of programming in C recently. Part of what comes with that is a lot of manual memory management. GCC and Clang have something called the cleanup attribute (among many other cool attributes that can be found here) that can be applied to variables. When a variable exits scope, a function — read more