Hand-written Windows API prototypes: fast, flexible, and tedious

I love fast builds, and for years I’ve been bothered by the build penalty for translation units including windows.h. This header has an enormous number of definitions and declarations and so, for C programs, it tends to dominate the build time of those translation units. Most programs, especially systems software, only needs a tiny portion of it. For example, when compiling u-config with GCC, two thirds of the debug build was spent processing windows.h just for 4 types, 16 definitions, and 16 prototypes.

[]

My favorite C compiler flags during development

This article was discussed on Hacker News and on reddit.

The major compilers have an enormous number of knobs. Most are highly specialized, but others are generally useful even if uncommon. For warnings, the venerable -Wall -Wextra is a good start, but circumstances improve by tweaking this warning set. This article covers high-hitting development-time options in GCC, Clang, and MSVC that ought to get more consideration.

[]

Practical libc-free threading on Linux

Suppose you’re not using a C runtime on Linux, and instead you’re programming against its system call API. It’s long-term and stable after all. Memory management and buffered I/O are easily solved, but a lot of software benefits from concurrency. It would be nice to also have thread spawning capability. This article will demonstrate a simple, practical, and robust approach to spawning and managing threads using only raw system calls. It only takes about a dozen lines of C, including a few inline assembly instructions.

[]

CRT-free in 2023: tips and tricks

Seven years ago I wrote about “freestanding” Windows executables. After an additional seven years of practical experience both writing and distributing such programs, half using a custom-built toolchain, it’s time to revisit these cabalistic incantations and otherwise scant details. I’ve tweaked my older article over the years as I’ve learned, but this is a full replacement and does not assumes you’ve read it. The “why” has been covered and the focus will be on the “how”. Both the GNU and MSVC toolchains will be considered.

[]

Let's implement buffered, formatted output

This article was discussed on reddit.

When not using the C standard library, how does one deal with formatted output? Re-implementing the entirety of printf from scratch seems like a lot of work, and indeed it would be. Fortunately it’s rarely necessary. With the right mindset, and considering your program’s actual formatting needs, it’s not as difficult as it might appear. Since it goes hand-in-hand with buffering, I’ll cover both topics at once, including sprintf-like capabilities, which is where we’ll start.

[]

Let's write a setjmp

This article was discussed on Hacker News.

Yesterday I wrote that setjmp is handy and that it would be nice to have without linking the C standard library. It’s conceptually simple, after all. Today let’s explore some differently-portable implementation possibilities with distinct trade-offs. At the very least it should illuminate why setjmp sometimes requires the use of volatile.

[]

My review of the C standard library in practice

This article was discussed on Hacker News and critiqued on Wandering Thoughts.

In general, when working in C I avoid the standard library, libc, as much as possible. If possible I won’t even link it. For people not used to working and thinking this way, the typical response is confusion. Isn’t that like re-inventing the wheel? For me, libc is a wheel barely worth using — too many deficiencies in both interface and implementation. Fortunately, it’s easy to build a better, simpler wheel when you know the terrain ahead of time. In this article I’ll review the functions and function-like macros of the C standard library and discuss practical issues I’ve faced with them.

[]

u-config: a new, lean pkg-config clone

This article was discussed on Hacker News.

In my common SDL2 mistakes listing, the first was about winging it instead of using the sdl2-config script. It’s just one of three official options for portably configuring SDL2, but I had dismissed the others from consideration. One is the pkg-config facility common to unix-like systems. However, the SDL maintainers recently announced SDL3, which will not have a sdl3-config. The concept has been deprecated in favor of the existing pkg-config option. I’d like to support this on w64devkit, except that it lacks pkg-config — not the first time this has come up. So last weekend I wrote a new pkg-config from scratch with first-class Windows support: u-config (“micro-config”). It will serve as pkg-config in w64devkit starting in the next release.

[]

SDL2 common mistakes and how to avoid them

This article was discussed on reddit.

SDL has grown on me over the past year. I didn’t understand its value until viewing it in the right lens: as a complete platform and runtime replacing the host’s runtime, possibly including libc. Ideally an SDL application links exclusively against SDL and otherwise not directly against host libraries, though in practice it’s somewhat porous. With care — particularly in avoiding mistakes covered in this article — that ideal is quite achievable for C applications that fit within SDL’s feature set.

[]

QOI is now my favorite asset format

This article was discussed on Hacker News.

The Quite OK Image (QOI) format was announced late last year and finalized into a specification a month later. Initially dismissive, a revisit has shifted my opinion to impressed. The format hits a sweet spot in the trade-off space between complexity, speed, and compression ratio. Also considering its alpha channel support, QOI has become my default choice for embedded image assets. It’s not perfect, but at the very least it’s a solid foundation.

[]

null program

Chris Wellons

wellons@nullprogram.com (PGP)
~skeeto/public-inbox@lists.sr.ht (view)