Articles on C
Last updated: 2023/01/16
Top deep-dives on C
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.
- 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
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.
"This booklet walks you through building the editor in 184 steps" in C.
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.
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.
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.
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.
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.
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.
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.
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!
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.
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.
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.
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.
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.
- 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
Chris Wellons illuminates the weirdness (read outdatedness) of the Windows runtime's command line argument passing.
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.
Noah Pendleton dives into C structure padding, explaining what it is, the current state of it, best practices, and the future.
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".
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.
Siddhesh Poyarekar explains how a common approach to pointer reallocation incorrectly breaks function fortification.
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.
Nima Badizadegan shows how division on the CPU can be accelerated using software to almost match hardware acceleration components.
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.
Chris Wellons explains how he developed the titular feature while trying out a memory reordering experiment in C11 and Go.
Nelson Elhage describes a bug related to creating child processes in Linux that was causing unexpected crashes in a small percentage of distributed jobs.
Drew DeVault ports DOOM to the Helios microkernel.
Martin Dørum "explore[s] how interpreters are often implemented, what a 'virtual machine' means in this context, and how to make them faster".
- 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
Chris Wellons implements the algorithm for checking credit card numbers in parallel using "SIMD within a register".
Laurence Tratt elaborates on the nuances of having blobs in cross platform executables.
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".
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.
"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.
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.
- 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