Skip to content
Tech News
← Back to articles

Sp.h is the standard library that C deserves

read original get C Standard Library Book → more articles
Why This Matters

The sp.h library aims to revolutionize C programming by providing a high-quality, portable standard library that interfaces directly with system calls, bypassing the limitations and cruft of libc. This approach empowers developers to write more efficient, low-level code and modernizes C's ecosystem for contemporary needs. Its development signifies a step forward in creating a leaner, more direct, and more powerful C programming experience for both industry and consumers.

Key Takeaways

Over the past year, I’ve been working on fixing C by giving it a high quality, ultra portable standard library. It is not a simple wrapper on top of libc; it doesn’t depend on libc except when required to by the platform. To my knowledge, there is nothing like it.

The library is called sp.h . It’s a 15,000 line, single header library written in plain C99. You can find the source code on GitHub, which includes the library itself, lots of example programs, and half a dozen baseball libraries which extend the core. If you prefer to read a few examples and look through the source, head to GitHub first. Otherwise, let’s get on with the pitch!

Table of Contents

Principles

Program directly against syscalls

The fundamental idea is that any C standard library must be written directly against the lowest level primitives available. It is neither useful nor productive to try to emulate, produce, or interface with the decades of cruft that have accumulated between the OS and the code that you yourself write.

Libc is actively harmful

It is tempting to conform to libc, because swaths of code promise to compile and run if you can simply provide an implementation of libc. But more and more, this is untrue.

Libc does not provide a useful interface for any program. Simple programs would rather use a high level language. Sophisticated programs cannot be written with the primitives that it provides. This has been exacerbated over the past decade as asynchronous programming has become more important. A “fast” program is becoming less about solving e.g. register allocation better than the other compiler and more about e.g. using the right kernel primitives to do IO.

Any interface upon which the fundamental unit of IO is FILE* or upon which a substring is a malformed idea is not just annoying. It’s harmful. sp.h casts it aside.

... continue reading