Lobsters Interview with matheusmoreira about Lone Lisp
extract
<p><a href="https://lobste.rs/~matheusmoreira" rel="ugc">@matheusmoreira</a> (<a href="https://www.matheusmoreira.com/" rel="ugc">blog</a>) built <a href="https://github.com/lone-lang/lone" rel="ugc">lone lisp</a> directly on Linux system calls. In this interview, he shares his knowledge of C and the Linux Kernel.</p> <hr /> <p><strong>How did you get into computing originally? What was your path before discovering Lisp etc.?</strong></p> <p>I've always liked computers, but what truly got me into programming was video games. When I was a kid, I used to play games from a series called Mega Man Battle Network, and I ended up getting inspired by those games. They're ultimately responsible for my learning English; I used to join forums as a non-English speaker and try to socialize. It was rough at the start but I improved! The same goes for my first language, C++.</p> <p><strong>How young were you when you started with C++?</strong></p> <p>In Brazil there are "technical schools" which is what I attended. They're normal highschool curriculum, with extra professional classes. I'm not sure if these are common abroad, if there is a term for it. There were other courses, also: chemistry, mechatronics... As for quality, it was basic, yet pretty good for a highschool level. It did make me start learning all by myself though; within 6 months, I'd already learned the entire curriculum. Eventually they hired me as a teacher's assistant to help fellow students.</p> <p>So when I started highschool, around 13-14, I took the informatics course and started learning C++ with a very old IDE called <a href="https://sourceforge.net/projects/orwelldevcpp/" rel="ugc">Dev-C++</a>, which still exists on source forge! I also browsed the tutorials on <a href="https://cplusplus.com" rel="ugc">cplusplus.com</a>. I tried making games but wasn't very successful at it! It was pretty hard, especially because I had yet to learn all the physics I was supposed to be simulating :) What I did end up doing was learning a lot more languages. After some basic C++ proficiency, I learned quite a bit of Java, then Ruby, then Python... That eventually led me to Lisp and Scheme! I remember thinking scheme was extremely elegant when I first saw it. Ruby was my favorite language though. I wrote a few gems back then. I think one actually got a small following: <a href="https://rubydoc.info/gems/acclaim/0.4.0" rel="ugc">Acclaim</a>, a git-like command based argument parser.</p> <p><strong>Cool! Did you happily jump into new languages or did you first try to stay with C++?</strong></p> <p>I think I started learning more languages after I exhausted the <a href="https://cplusplus.com" rel="ugc">cplusplus.com</a> tutorials. I felt if there was nothing else for me to learn on that site, then I should probably move on, right? Sun used to have a really big Java Tutorials website back then. I think I read that entire site. That was when I learned object-oriented programming. I wrote some java code as a teenager... Some "utilities libraries". In hindsight, it was just a badly implemented version of 1% of what Apache commons has! I think I even published it, might still be out there somewhere... I also remember experimenting a lot with Java Swing applications. I used to really like the Nimbus look and feel and made a circle/arc drawing application for my math professor once.</p> <p><strong>What motivated all of these delvings? What inspired you to keep checking out different languages and so on? Have you stuck with Ruby too?</strong></p> <p>School projects were a big motivator in my early school years, but at some point it was about curiosity, and a desire for The Right Thing. I wanted a language to call home. I stuck with Ruby the longest. It's a really nice language. I always have it installed, and have recently started a Rails project! But it has its imperfections too. The other language that I stuck with was C. Its low level simplicity was really captivating to me.</p> <p>I didn't forget C++, but I also didn't update my knowledge. Current C++ is essentially a completely new language, so I no longer claim I know C++. In a sense, I replaced it with C. C was always captivating for some reason, despite all the problems and legacy, but it really started getting entrenched in my mind when I started exploring the CRuby VM source code as a teenager. I had this really fun past time where I'd watch for interesting stackoverflow questions where someone would ask "why does Ruby act like X?" and I'd dig into the source code to figure it out.</p> <p>A few years ago I tried to transition to Rust, but it didn't quite stick. I'm also a huge fan of Zig and its creator. Have been since I watched "the road to Zig 1.0" keynote where he laid down reasons why people "rewrite things in C": speed, ABI...</p> <p><strong>What pros and cons kept you with C and Ruby?</strong></p> <p>Ruby was an extremely expressive language which "just fit" with my mental model. I could often guess a method name and it would work. It has nice things like singular/plural forms of method names, synonyms. Our brains work with these words, and Ruby supports them all.</p> <p><strong><a href="https://alexalejandre.com/interviews/interview-with-matklad/" rel="ugc">Matklad</a> mentioned good APIs should be guessable and if he guesses stuff which don't exist, he'll often file a bug report saying the API demands it!</strong></p> <p>Ruby also enables composing eerily shell-like processing pipelines... items.each.with_index.map... It just keeps composing and you can do a LOT of work with very few characters.</p> <p>For C, the main advantage is the simplicity of the output. You write a function, it compiles to an ELF symbol and associated assembly code. They say you can see the compiler output when you write C, and it's true. With C++ the compiler adds a lot of machinery, it's very difficult to understand how it all fits together. With dynamic languages, it's just the same, but I found it easier to explore the source code of virtual machines than that of compilers.</p> <p><strong>So your C++ style changed, removing sugar until you were writing C?</strong></p> <p>Yes. My style also changed as I read more and more code written by other developers. I've explored CRuby code, CPython code, JVM code, a bit of guile code, even a bit of V8 code... I started to really admire expert C programmers when I started reading Linux kernel source code though. It's really good, probably the gold standard.</p> <p><strong>From the beginning, you read a lot? It's quite rare particularly today for people to really read others' code. How do you approach this? Any tricks or techniques?</strong></p> <p>I read a lot. I've always been the sort of curious person who wanted to know how the thing worked. I wasn't satisfied with just using some library, I wanted to know what it was doing under the hood. I wanted to know how the drivers talked to the hardware. I wanted to know all the hidden fun stuff. That's just the sort of thing that's interesting to me. The real applications I tried to make, I'd end up digressing into these unrelated explorations. Other programmers would tell me "why waste time on that? it's already solved" but I wanted to know how it was done, and eventually I also started to develop a sort of hubris that led me to want to reinvent the wheel, but better.</p> <p>I did get the message though. I felt like I was a bad fit for a career in software development because of this quirk, so I didn't pursue one in the end. Kept it as my hobby to this day.</p> <p><strong>When you first looked at driver code, how'd you make heads and tails of it all?</strong></p> <p>I couldn't make heads or tails of it all... at first. It was frustrating, but I kept persisting and eventually I was able to understand <em>some</em> things, at least. I'm no hardware engineer, that's for sure... But I managed to reverse engineer some of my laptop's features. Still one of my proudest projects. My laptop is one of those Clevo barebones models. It has a pretty nice keyboard with RGB LEDs, most individually addressable. There was a REALLY bad windows app to control those LEDs. I swear it took over a minute to show a window on the screen, it was really aggravating. I used wireshark to intercept the USB packets it was sending to the keyboard and write a linux user space driver for it. I captured the packets, stared at the screen until I figured out their structure, and wrote a little C program to configure the keyboard for me. Threw it out on github and forgot about it... One day I went back there and somehow people were using the thing, one person even made a GUI for it. It was a pretty good feeling. I learned more about drivers and computer technology from trying to reverse engineer the rest of the laptop's features. ACPI power management stuff. I didn't quite figure everything out though, to this day.</p> <p><strong>You have an <a href="https://www.matheusmoreira.com/articles/linux-system-calls" rel="ugc">article about linux system calls</a>, was that the moment you took the lone direction?</strong></p> <p>The code for system calls is pretty minimal, they work like normal function calls. I'd say the interesting part is that it allows you to bypass <code>libc</code> and target <a href="https://news.ycombinator.com/item?id=29106179" rel="ugc">linux directly</a>. Linux is famous for user space ABI stability; userspace components not so much. It allows people to depend on Linux kernel directly, without other things in-between.</p> <p>I started with this general sense that people didn't want me to use them. I'd read the manuals and they'd say things like "this system call is not supported by glibc". I'd read wikipedia and there'd be an infograph is howing <code>glibc</code> wrapping linux, as though it was the CRT of Linux and other <code>libc</code>s didn't exist. Then I read an article on the LWN about how it took like two years for the <code>getrandom</code> system call to show up on glibc.</p> <p><strong>CRT?</strong></p> <p>C runtime. The standard C library: glibc, musl, uclibc.</p> <p>It's that package which breaks the entire world whenever they break compatibility. Because everything depends on it. I remember the article mentioned something like "maybe Linux should have a liblinux.a with just the syscalls, then people can bypass libc when they aren't helping by just passing <code>-llinux</code> to the compiler". I thought that was a really cool project idea so I went and created liblinux, which was just that: a collection of linux system call wrappers for freestanding C programming. It turned out that it was really fun to program against the Linux system call interface. So many of C's problems just disappear in freestanding mode.</p> <p><strong>What C problems disappear in freestanding mode?</strong></p> <p>The most basic one: <code>errno</code>. C has this notion of a "current error" which is a global variable. Every function sets it, and you're supposed to check it. Linux just returns you that error like a normal function would. The C libraries take that value, and put it in a global variable. It's just the way things are in C. Not in freestanding C. The legacy of C also disappears too. The C library has a lot of legacy code in it. The locale stuff, for example, is extremely problematic. It's also global state (a recurring theme!) which can cause very subtle errors based on things like environment variables. Liblinux taught me freestanding C, and how clean C could be... If only we could delete all of its legacy. It was painful. I had to write all of my own functions. From basic bytes copying functions, to integer->string conversion functions... The problem turned out to not be as insurmountable as I imagined though, and I persisted. I knew that when in doubt, I could always read code. I could see how the giants before me did it. The <code>glibc</code> repository was difficult to interpret but the <code>musl libc</code> source code is really clean and easy to dive into. It's been invaluable! It also stimulated a bit of creativity. For example, how could I create an automated test suite with no C library, no memory allocations, just static memory? I managed to do it in lone!</p> <p>I remember I even asked <a href="https://en.wikipedia.org/wiki/Greg_Kroah-Hartman" rel="ugc">Greg Kroah-Hartman</a> on Reddit about why Linux never had an "official" C library. He replied that Linux once had a <a href="https://en.wikipedia.org/wiki/Klibc" rel="ugc">klibc</a> project! The history of <code>liblinux</code> ended though: At some point I discovered Linux kernel folks were doing the very same thing! They had created a <a href="https://elixir.bootlin.com/linux/v6.2-rc4/source/tools/include/nolibc/nolibc.h" rel="ugc">nolibc.h</a> file that they were using internally in their own tools. I thought it was better than what I had come up with, and easier to use too. So I archived the project, and started something else: <a href="https://github.com/lone-lang/lone" rel="ugc">Lone Lisp</a>. A whole programming language written in that paradigm. Deep down, I just wanted to prove to myself that I wasn't insane to think it was possible. If I could make a freestanding lisp that ran directly on linux, it would prove that any program could be written that way.</p> <blockquote> <p>Modern Linux user space is monstrous and labyrinthine. Linux itself is not. I found it to be a really clean system. The basis of everything is actually the Linux system call binary interface. We can actually trash the entire user space and start from scratch with nothing but Linux. We can even trash the ubiquitous GNU stuff if we want.</p> <p>Why can't we have a compiler with built in system call support? Just add a system_call keyword that inlines Linux system call code using the supplied parameters. No need for libc bullshit in the middle. No need for C or any specific language. Someone could make a language today and that single feature would make it as capable as C is for systems programming. They could write software and boot Linux directly into it. <a href="https://news.ycombinator.com/item?id=28283632" rel="ugc">- Matheus 2021</a></p> </blockquote> <p>To summarize, freestanding C removes some interesting C warts: all global state: <code>errno</code>, <code>rand</code>/<code>srand</code> state, locale state, <code>strtok</code> (not <code>reentrant</code>!), implicit file buffering which can occasionally bite people; badly designed APIs like gets (indefensible), <code>atexit</code>, <code>signal</code>, even <code>malloc</code>; lone's allocator is much nicer. <code>math.h</code> can get very messy with NaN, and it gets worse when <code>errno</code> is involved. Some things just never leave though. C's arcane integer promotion rules remain. Also the lack of overflow checking, but I use compiler builtins for those. I also worry a lot that I might be introducing my own warts... Hubris will no doubt bite me one day.</p> <p><strong>Do you know why the <code>nolibc.h</code> approach isn't more popular?</strong></p> <p>As of now, nolibc.h has become a sprawling directory in the kernel tree, it has become an ad-hoc libc of sorts. It seems they treat it as an internal project though, something meant to compile the internal tools linux uses. I think very few people outside linux kernel development know it exists. People could totally use it to build their own projects, but I'm not sure what sort of stability guarantees Linux offers in that regard.</p> <p>Relatedly, I've sent Cosmopolitan patches e.g. to help implement floating point parsing. I'm a fan of the project and the author. Even the people calling it a "dumb" hack are admitting that it's a genius hack as far as I'm concerned. It's just an amazing project that just coalesced an incredible amount of very wizardly knowledge into a single form which is the APE format. Something that manages to parse as a valid executable on various platforms with different executable formats is a very curious thing indeed. And it even does neat things on top of that, supports embedded archives in executables.</p> <p><strong>It's important to at least be thinking about hubris and how to avoid warts, hopefully. Many never introspect... Floating point's the only unchecked lone feature, what happens after? Do you want to build particular things in it.</strong></p> <p>As Steve Yegge said, just creating an interpreter creates a baby, a lifetime of work. Floating point is gonna be a hard one, but the work forward is literally unbounded.</p> <p>Just this weekend I implemented the error handling system. It's a Common Lisp style restartable condition system. Before that, every error path was a hard exit(255) from the interpreter. My next task is to replace all of those call sites with exceptions that can be handled within lisp. I also pushed proper tail call optimization support just now... Floating point is going to be a hard feature, if the patch I sent to Cosmopolitan is any indication. It's something I'll have to implement though. I also want to eventually start implementing ideas from the Erlang/BEAM system. I structured it so that there could one day be many interpreters running lisp code in parallel. Those are all language level features.</p> <p>What to build with the language itself? The very first project I want to make with lone... Is a replacement for my static site generator. I write my website in a fork of pugjs which I've been maintaining myself. It's my long term goal to write my own system in lone lisp to replace it. After that, I want to write my own shell. My own utilities. Start remaking the traditional Linux user space in my image.</p> <p>Those were the ideas that float around in my mind while I develop lone. One of my articles even mentions an implementation of <code>env</code> which just dumps the environment as a lone lisp table. Lone didn't have any iteration facilities at the time, so that was the best I could do. Now lone has generators! I can do a lot more... It's such a good feeling when I implement something and it just unlocks a lot of other stuff. The embedded segment feature is something I designed precisely for that "linux utility" use case. The lone interpreter has a feature where it reads a special ELF segment and just runs the code there, as though it was compiled in. So I can make lone programs by copying the interpreter, adding some lisp code to the copy, and it becomes a self-contained program. It's now got generators, delimited continuations, and I just introduced error handling.</p> <p><strong>How similar is the new error system to Common Lisp's??</strong></p> <p>The error system is similar in many ways but without the Common Lisp API where the signaling code gives options on how to restart, options like use-value. My system builds directly on top of the delimited continuation work. Until implementing them, continuations were just one of those mystical scheme features but I discovered that everybody was already using a version of it. Exceptions mechanisms are essentially a form of continuations, they just don't get captured into a value. And the magic is capturing the continuation. Alexis King's presentation on delimited continuations demystified that for me, it demonstrated that in the end it was just <code>memcpy</code>ing stacks. Making a copy of the stack, then "replaying" that stack somewhere else, like a VCR. Resumable exceptions. The error signaling system turned out to be just this, with a handler mechanism on top. I had to implement the "catch ErrorType -> code for ErrorType" part. I chose a simple system just mapping, say, a symbol like <code>'not-found</code>, to a lambda. So it tests the lambda's arity and if it takes one argument: <code>(lambda (error) ...)</code> it works just like every other language out there. But if it takes two: <code>(lambda (error continuation) ...)</code> then it provides a way to resume the code via continuations.<
retained text (truncated)
<p><a href="https://lobste.rs/~matheusmoreira" rel="ugc">@matheusmoreira</a> (<a href="https://www.matheusmoreira.com/" rel="ugc">blog</a>) built <a href="https://github.com/lone-lang/lone" rel="ugc">lone lisp</a> directly on Linux system calls. In this interview, he shares his knowledge of C and the Linux Kernel.</p> <hr /> <p><strong>How did you get into computing originally? What was your path before discovering Lisp etc.?</strong></p> <p>I've always liked computers, but what truly got me into programming was video games. When I was a kid, I used to play games from a series called Mega Man Battle Network, and I ended up getting inspired by those games. They're ultimately responsible for my learning English; I used to join forums as a non-English speaker and try to socialize. It was rough at the start but I improved! The same goes for my first language, C++.</p> <p><strong>How young were you when you started with C++?</strong></p> <p>In Brazil there are "technical schools" which is what I attended. They're normal highschool curriculum, with extra professional classes. I'm not sure if these are common abroad, if there is a term for it. There were other courses, also: chemistry, mechatronics... As for quality, it was basic, yet pretty good for a highschool level. It did make me start learning all by myself though; within 6 months, I'd already learned the entire curriculum. Eventually they hired me as a teacher's assistant to help fellow students.</p> <p>So when I started highschool, around 13-14, I took the informatics course and started learning C++ with a very old IDE called <a href="https://sourceforge.net/projects/orwelldevcpp/" rel="ugc">Dev-C++</a>, which still exists on source forge! I also browsed the tutorials on <a href="https://cplusplus.com" rel="ugc">cplusplus.com</a>. I tried making games but wasn't very successful at it! It was pretty hard, especially because I had yet to learn all the physics I was supposed to be simulating :) What I did end up doing was learning a lot more languages. After some basic C++ proficiency, I learned quite a bit of Java, then Ruby, then Python... That eventually led me to Lisp and Scheme! I remember thinking scheme was extremely elegant when I first saw it. Ruby was my favorite language though. I wrote a few gems back then. I think one actually got a small following: <a href="https://rubydoc.info/gems/acclaim/0.4.0" rel="ugc">Acclaim</a>, a git-like command based argument parser.</p> <p><strong>Cool! Did you happily jump into new languages or did you first try to stay with C++?</strong></p> <p>I think I started learning more languages after I exhausted the <a href="https://cplusplus.com" rel="ugc">cplusplus.com</a> tutorials. I felt if there was nothing else for me to learn on that site, then I should probably move on, right? Sun used to have a really big Java Tutorials website back then. I think I read that entire site. That was when I learned object-oriented programming. I wrote some java code as a teenager... Some "utilities libraries". In hindsight, it was just a badly implemented version of 1% of what Apache commons has! I think I even published it, might still be out there somewhere... I also remember experimenting a lot with Java Swing applications. I used to really like the Nimbus look and feel and made a circle/arc drawing application for my math professor once.</p> <p><strong>What motivated all of these delvings? What inspired you to keep checking out different languages and so on? Have you stuck with Ruby too?</strong></p> <p>School projects were a big motivator in my early school years, but at some point it was about curiosity, and a desire for The Right Thing. I wanted a language to call home. I stuck with Ruby the longest. It's a really nice language. I always have it installed, and have recently started a Rails project! But it has its imperfections too. The other language that I stuck with was C. Its low level simplicity was really captivating to me.</p> <p>I didn't forget C++, but I also didn't update my knowledge. Current C++ is essentially a completely new language, so I no longer claim I know C++. In a sense, I replaced it with C. C was always captivating for some reason, despite all the problems and legacy, but it really started getting entrenched in my mind when I started exploring the CRuby VM source code as a teenager. I had this really fun past time where I'd watch for interesting stackoverflow questions where someone would ask "why does Ruby act like X?" and I'd dig into the source code to figure it out.</p> <p>A few years ago I tried to transition to Rust, but it didn't quite stick. I'm also a huge fan of Zig and its creator. Have been since I watched "the road to Zig 1.0" keynote where he laid down reasons why people "rewrite things in C": speed, ABI...</p> <p><strong>What pros and cons kept you with C and Ruby?</strong></p> <p>Ruby was an extremely expressive language which "just fit" with my mental model. I could often guess a method name and it would work. It has nice things like singular/plural forms of method names, synonyms. Our brains work with these words, and Ruby supports them all.</p> <p><strong><a href="https://alexalejandre.com/interviews/interview-with-matklad/" rel="ugc">Matklad</a> mentioned good APIs should be guessable and if he guesses stuff which don't exist, he'll often file a bug report saying the API demands it!</strong></p> <p>Ruby also enables composing eerily shell-like processing pipelines... items.each.with_index.map... It just keeps composing and you can do a LOT of work with very few characters.</p> <p>For C, the main advantage is the simplicity of the output. You write a function, it compiles to an ELF symbol and associated assembly code. They say you can see the compiler output when you write C, and it's true. With C++ the compiler adds a lot of machinery, it's very difficult to understand how it all fits together. With dynamic languages, it's just the same, but I found it easier to explore the source code of virtual machines than that of compilers.</p> <p><strong>So your C++ style changed, removing sugar until you were writing C?</strong></p> <p>Yes. My style also changed as I read more and more code written by other developers. I've explored CRuby code, CPython code, JVM code, a bit of guile code, even a bit of V8 code... I started to really admire expert C programmers when I started reading Linux kernel source code though. It's really good, probably the gold standard.</p> <p><strong>From the beginning, you read a lot? It's quite rare particularly today for people to really read others' code. How do you approach this? Any tricks or techniques?</strong></p> <p>I read a lot. I've always been the sort of curious person who wanted to know how the thing worked. I wasn't satisfied with just using some library, I wanted to know what it was doing under the hood. I wanted to know how the drivers talked to the hardware. I wanted to know all the hidden fun stuff. That's just the sort of thing that's interesting to me. The real applications I tried to make, I'd end up digressing into these unrelated explorations. Other programmers would tell me "why waste time on that? it's already solved" but I wanted to know how it was done, and eventually I also started to develop a sort of hubris that led me to want to reinvent the wheel, but better.</p> <p>I did get the message though. I felt like I was a bad fit for a career in software development because of this quirk, so I didn't pursue one in the end. Kept it as my hobby to this day.</p> <p><strong>When you first looked at driver code, how'd you make heads and tails of it all?</strong></p> <p>I couldn't make heads or tails of it all... at first. It was frustrating, but I kept persisting and eventually I was able to understand <em>some</em> things, at least. I'm no hardware engineer, that's for sure... But I managed to reverse engineer some of my laptop's features. Still one of my proudest projects. My laptop is one of those Clevo barebones models. It has a pretty nice keyboard with RGB LEDs, most individually addressable. There was a REALLY bad windows app to control those LEDs. I swear it took over a minute to show a window on the screen, it was really aggravating. I used wireshark to intercept the USB packets it was sending to the keyboard and write a linux user space driver for it. I captured the packets, stared at the screen until I figured out their structure, and wrote a little C program to configure the keyboard for me. Threw it out on github and forgot about it... One day I went back there and somehow people were using the thing, one person even made a GUI for it. It was a pretty good feeling. I learned more about drivers and computer technology from trying to reverse engineer the rest of the laptop's features. ACPI power management stuff. I didn't quite figure everything out though, to this day.</p> <p><strong>You have an <a href="https://www.matheusmoreira.com/articles/linux-system-calls" rel="ugc">article about linux system calls</a>, was that the moment you took the lone direction?</strong></p> <p>The code for system calls is pretty minimal, they work like normal function calls. I'd say the interesting part is that it allows you to bypass <code>libc</code> and target <a href="https://news.ycombinator.com/item?id=29106179" rel="ugc">linux directly</a>. Linux is famous for user space ABI stability; userspace components not so much. It allows people to depend on Linux kernel directly, without other things in-between.</p> <p>I started with this general sense that people didn't want me to use them. I'd read the manuals and they'd say things like "this system call is not supported by glibc". I'd read wikipedia and there'd be an infograph is howing <code>glibc</code> wrapping linux, as though it was the CRT of Linux and other <code>libc</code>s didn't exist. Then I read an article on the LWN about how it took like two years for the <code>getrandom</code> system call to show up on glibc.</p> <p><strong>CRT?</strong></p> <p>C runtime. The standard C library: glibc, musl, uclibc.</p> <p>It's that package which breaks the entire world whenever they break compatibility. Because everything depends on it. I remember the article mentioned something like "maybe Linux should have a liblinux.a with just the syscalls, then people can bypass libc when they aren't helping by just passing <code>-llinux</code> to the compiler". I thought that was a really cool project idea so I went and created liblinux, which was just that: a collection of linux system call wrappers for freestanding C programming. It turned out that it was really fun to program against the Linux system call interface. So many of C's problems just disappear in freestanding mode.</p> <p><strong>What C problems disappear in freestanding mode?</strong></p> <p>The most basic one: <code>errno</code>. C has this notion of a "current error" which is a global variable. Every function sets it, and you're supposed to check it. Linux just returns you that error like a normal function would. The C libraries take that value, and put it in a global variable. It's just the way things are in C. Not in freestanding C. The legacy of C also disappears too. The C library has a lot of legacy code in it. The locale stuff, for example, is extremely problematic. It's also global state (a recurring theme!) which can cause very subtle errors based on things like environment variables. Liblinux taught me freestanding C, and how clean C could be... If only we could delete all of its legacy. It was painful. I had to write all of my own functions. From basic bytes copying functions, to integer->string conversion functions... The problem turned out to not be as insurmountable as I imagined though, and I persisted. I knew that when in doubt, I could always read code. I could see how the giants before me did it. The <code>glibc</code> repository was difficult to interpret but the <code>musl libc</code> sourc
document fetched 2026-07-19 08:00 · canonical https://alexalejandre.com/interviews/interview-with-matheus-moreira