Language Showcase: C3
C3 is a C-like language striving to be an evolution of C, rather than a completely new language.
C3 is a systems programming language based on C. It’s an evolution of C enabling the same paradigms and retaining the same syntax as far as possible. For today’s language showcase, C3’s developer, Christoffer Lernö, talks about what makes it tick.
How would you describe C3 to the average programmer?
C3 is an evolution of C: “what could C look like if backwards compatibility wasn’t a concern?”. The main additions are modules, slices and semantic macros, but otherwise it tries to stay close to the look-and-feel of C. Most importantly, it is ABI compatible with C everywhere, meaning functions in C3 are by default callable from C and vice versa.
You don’t have to rewrite everything in C3, you can pick and choose.
Which problems is C3 trying to solve?
C has the burden of backwards compatibility and while it’s possible to add features on top, it’s hard to make them nicely integrated in the overall language. Some parts of C (in particular string handling and arrays) aren’t very ergonomic and makes the language seem harder to use than it needs to be. So it’s about making C programming more accessible and less punishing by providing better tools for the pain points in C.
What makes C3 unique?
I don’t know if it is! There are a couple of ”C replacement languages” in development right now: Odin, Jai, Zig and Hare to name a few. What they have in common is that they diverge quite a bit from C syntax and semantics.
C3 is different: you can just lift your C code with just a few changes into C3 and have it run as expected.
What are some of the toughest challenges with building C3?
I’d love to have more people invested in the project with strong language design sensibilities to bounce ideas off. I love a good argument to be able to narrow down on the essentials of a feature. Luckily there are forums for budding programming language designers to trade ideas which helps. But that’s not quite the same as having someone who really wants to help YOUR language.
The programming is the easy part.
What's next for C3?
Work on expanding the standard library, I’d like to reach the point where people can feel it has all the necessary basics.
Where can people learn more?
The docs can be found at https://www.c3-lang.org and the compiler can be found on Github: https://github.com/c3lang/c3c
Which languages inspired yours the most?
C2, by Bas van den Berg. My first compiler work was actually contributing to the C2 compiler! While Bas wanted a more modest feature set on top of C, I thought more ideas should be tested, and initially C3 was just C2 + some more features. When I decided to write a compiler for my ideas, I picked the name C3 to acknowledge its origins.
Program comparison: arithmetic
Prompt: Implement a program which takes in a single string from stdin containing a basic arithmetic expression, such as “1 + 2 - 5”, evaluate it, and print the result.
I like the idea of a next evolution of C, there are also many features in the example code I’d like to use. The only thing I got stuck irritating myself about is the “fn” prefix for defining functions. It is completely redundant as the parser can figure out that it’s a new function, even C can do this with LR(1).
I also don’t like the idea of going through each of my functions prepending this new keyword (must be done manually as C doesn’t have a keyword to search for).
To get old C folks to switch to C3, minimize the level of effort to make that change. It’s hard to do that I know, but forcing developers to refactor large code based or even legacy code will probably result in less popularity. The best case (and probably the better solution) would be to write a C99 to C3 transpiler.
I loved the interview and everything else, but felt that I needed to speak my mind. Good luck!