Articles on C

Last updated: 2023/01/16

Top deep-dives on C

goto hell;

Christopher Bazley argues that the use of goto statements in C programming is not as effective as other methods of error handling, despite being a widely used practice. Christopher cites several examples of why this is the case and argues that programmers should be more open to other methods of error handling.
Some highlights:

  • goto should only really be used to abandon processing in some deeply nested structure, such as breaking out of two or more loops at once
  • Deferred error handling > Error handling by early exit from a function

Stop checking for NULL pointers!

When working with a lower level language like C, it is easy to cause problems that might make your whole program or system crash. So intuitively, you'd think we'd want checks to make sure these problems don't occur in the code we right. However,  in this article, Elad Lahav discusses how checking for one of such cases is actually detrimental in that it might lead to a false sense of security.

Build Your Own Text Editor

"This booklet walks you through building the editor in 184 steps" in C.

Defensive Programming - Friend or Foe?

Bugs are the bane of most software. It's especially bad when they cause the software to go into some unexpected or undefined state. In this article, Tyler Hoffman describes a more proactive and aggressive approach to catching and reporting bugs in embedded systems, compared to merely making sure bugs don't cause complete crashes.

Linear Algebra Shenanigans: Gizmo Repair

Spotting problems and debugging them is as important in programming (if not more) as is writing the code in the first place. Obviously it would be better to not write buggy code in the first place, but sometimes that's out of your control. Fortunately Karl Zylinski has written an article about spotting an issue, narrowing down the problem space, adding visuals to help debug, and the ultimate solution, all for a game engine written in C.

Making Mass Effect not require administrator rights, or maybe how to not write a boolean check

Unfortunately I never got into modding video games (I wish I had, would've been fun), but that doesn't make me appreciate any less what what those devs do. Especially when you see some of the stuff they have to root around in. In this lengthy article, the author takes us along on a quest to discover the source of a register value issue triggering an unwanted action in a PC port of Mass Effect.

Making our own ping

But Alex, this is from almost a year ago! And it doesn't even link to a specific article! Blah reader! It might be... matured, and yes, there isn't a specific article at the link, there are 14! That's right, Amos has written a 14 part series on building your own ping, which starts from a short history of computer networking and culminates in crafting ICMP-bearing IPv4 packets with the help of bitvec. Looking as this essentially covered my entire class on networking in college, I figured it was worth sharing.

Writing a "bare metal" operating system for Raspberry Pi 4

Have you ever wanted to build an OS from scratch? No? Well that doesn't matter, because you can just read this series of interactive articles by Adam Greenwood-Byrne. Although shrouded in the guise of a tutorial, it's by no means a how-to, and Adam covers everything from bootstrapping to WordUp Graphics, all the while littering gems of knowledge along the way.

Writing a simple 16 bit VM in less than 125 lines of C

Title really says it all. Andrei Ciobanu starts with the basics of what a virtual machine is covers every step in the journey of implementing one.

Programming Style Influences

Not really a deep-dive, but I think it covers a subject that isn't much covered in programming. Laurence Tratt discusses how OpenBSD influenced his coding style and what people who write code have to gain from seeking out such influences.

Implementing Hash Tables in C

Really, the title says it all. Is this extensive article by Andrei Ciobanu something your college professor would recommend? Probably. Does that make it any worse? Not really. Andre briefly covers hash functions, then begins taking apart the implementation of the hash table, starting with separate chaining. The article is still in draft form, but has good info, and gives you an opportunity to make comments on improvements/additions!

Let's write a compiler, part 1: Introduction, selecting a language, and doing some planning

Want to write your own compiler? Well I bet Brian Robert Callahan's seroes can help. In this first part, Brian sets out the specifications for what the compiler is going to be able to do, what language to implement it in, and lays out a couple of diagrams for the overall process flow for the compiler.

Chain loading, not preloading: the dynamic linker as a virtualization vector

Executable and Linkable Format (ELF), is a common standard file format for executable files, object code, shared libraries, and core dumps. In this technical article, Dr Stephen Kell shows how to "run a pre-existing binary program but in some kind of instrumented or modified form" using "ELF-level trickery", which essentially means writing a dynamic linker rather than using LD_PRELOAD.

A Bonding Exercise

The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical "bonded" interface. Patrik Lundin and his colleague were experimenting with one of these bonded interfaces when they noticed that the MAC address of the interface would change on network restart. This article details their quest for determining the cause.

Leveraging LD_AUDIT to Beat the Traditional Linux Library Preloading Technique

Windows gets a lot of crap (*cough* neckbeards *cough*) for being a breeding cesspool of vulnerabilities and their respective viruses, but Linux has its own vulnerabilities too. What are these you ask? Well Lior Ribak has written an interesting article that explores on such vulnerability. Lior discusses how using an uncommon 'feature of the dynamic linker/loader' to force all ' dynamic executables in [the] environment' to load a shared library can be defended against by another similar feature, that can be forced to load even earlier. Lior also goes into the offensive uses.

Untangling Lifetimes: The Arena Allocator

Ryan Fleury illuminates his dislike of how it's the norm for everyone to be taught to stay away from manual memory management in C. Ryan argues that this way of thinking is nonsensical and that it's not necessary to introduce "automatic reference counting, RAII, and/or garbage collectors" as alternatives when there are simpler solutions, like the arena allocator.
Some highlights:

  • Malloc and free should rarely become the defacto memory management interfaces for a codebase
  • Memory leaks are "erased" when the program that created them errors or crashes
  • No easy way to mass free all mallocs relating to something
  • The general gist of the arena allocator is to use independent stacks to bucket memory allocations together

The wild west of Windows command line parsing

Chris Wellons illuminates the weirdness (read outdatedness) of the Windows runtime's command line argument passing.

My Own Private Binary

How far would you go to make the smallest executable possible? Would you write your own kernel module? No? Well that's what Brian Raiter did, and now has written an article about it. In it, Brian demonstrates all of the necessary steps to get your kernel accepting a nonstandard Linux binary format.

C Structure Padding Initialization

Noah Pendleton dives into C structure padding, explaining what it is, the current state of it, best practices, and the future.

[OpenGL and Vulkan Interoperability on Linux] Part 2: Using OpenGL to draw on Vulkan textures.

As someone who has installed Arch Linux on two laptops that had two GPUs and did a deep dive over several months into machine learning on the GPU, I'm pretty familiar with the big GPU libraries. But I'll be the first to admit that my knowledge is limited to only a higher-level understanding. Fortunately, there are 10 part series like this one by Eleni Maria Stea that get down and dirty in the details of OpenGL and Vulkan. In this part of the series, Eleni demonstrates how "Vulkan/GL interoperability" can be achieved "where an image is allocated using Vulkan and filled using OpenGL".

Page Fault Injection in Virtual Machines: Accessing Swapped-Out Pages from HVMI

Andrei Lutas discusses how page fault injection allows Hyper Memory Introspection to analyze normally unreachable guest memory that has been swapped-out of physical memory.

That is not a number, that is a freed object

Siddhesh Poyarekar explains how a common approach to pointer reallocation incorrectly breaks function fortification.

Fast CSV processing with SIMD

If you’re working with csv data using standard UNIX tools like awk, sed, sort, etc. then you might run into issues with embedded commas and newlines being incorrectly interpreted as separators. In this concise article, Chris Wellons demonstrates his own optimized implementation of a library that helps you handle these issues and explains how he went about optimizing it.

Racing the Hardware: 8-bit Division

Nima Badizadegan shows how division on the CPU can be accelerated using software to almost match hardware acceleration components.

My take on "where's all the code"

Chris Wellons discusses some of the design choices and interesting aspects of implementing his own program in C that counts the lines of code in each part of a source tree.

A flexible, lightweight, spin-lock barrier

Chris Wellons explains how he developed the titular feature while trying out a memory reordering experiment in C11 and Go.

Made of Bugs

Nelson Elhage describes a bug related to creating child processes in Linux that was causing unexpected crashes in a small percentage of distributed jobs.

Porting Doom to Helios

Drew DeVault ports DOOM to the Helios microkernel.

Faster virtual machines: Speeding up programming language execution

Martin Dørum "explore[s] how interpreters are often implemented, what a 'virtual machine' means in this context, and how to make them faster".
Some highlights:

  • An interpreter is a type of virtual machine that reads and executes code
  • Many programming languages have a front-end compiler that emits bytecode, which is then executed by a virtual machine
  • The techniques described in this post won't magically make any interpreted language much faster

Luhn algorithm using SWAR and SIMD

Chris Wellons implements the algorithm for checking credit card numbers in parallel using "SIMD within a register".

What's the Most Portable Way to Include Binary Blobs in an Executable?

Laurence Tratt elaborates on the nuances of having blobs in cross platform executables.

Porting libffi to pure WebAssembly

Cheng Shao "introduces libffi, the challenges to make it work with WebAssembly, demonstrates [their] implementation, and also explains how it’s used by GHC runtime".

Linux in a Pixel Shader - A RISC-V Emulator for VRChat

This has been around for a bit, but thought it was still worth putting in here. You ever wanted to run Linux in VR chat? Like have it running right there in front of your eyes in your GPU? No? We'll you're clearly not a dreamer like Stefan. In this informative article, Stefan goes through the ins and outs of what it took to get CPU emulator with Linux running in VR chat.

Je Ne Sais Quoi - Falcons over the Horizon

"Falcon stands for FAst Logic CONtroller and is a proprietary microprocessor developed by Nvidia". Its first use was in GPUs from the G98 series, but has since been repurposed and reused for other series too. Mike Heskin and Michael have written a super in-depth article on hacking the Falcon. It really has everything you'd want to know, so check it out.

Code specialization for the MIR lightweight JIT compiler

Vladimir Makarov "discuss[es] how [he] plan[s] to support the generation of specialized and deoptimized code in MIR, and what support has already been implemented in the MIR project".


Saar Amar presents how Apple has added a new security measure to their iOS and macOS operating systems in the form of "guards" for certain types of allocations.
Some highlights:

  • These guards are designed to help secure atomic allocations, and work by comparing a mapping entry associated with the allocation to a new guard structure
  • They help prevent "powerful memory corruption" via the allocator
  • This change was added in iOS 16 / macOS 13

Want to see more in-depth content?

subscribe to my newsletter!

Other Articles