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.
Thanks for reading Compiler Spotlight! Subscribe for free to hear about new language showcases.
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?
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.