How to Write Anything in C

Viktor Daróczi
8 min readApr 25, 2022
Photo by Vincentiu Solomon on Unsplash

C is probably the most underrated language. It’s often considered obsolete, not hip, not fancy, not trendy, not cool. Yet C drives the whole world. It’s like oxygen in software development. If it disappeared all of a sudden one day, nothing would work anymore. Name any software, any programming language, I bet you will find C in its core if you dig deeply enough. Even better than that, most of the C code is written by volunteers for free.

To demonstrate these claims and pay homage to C’s contribution, I collected some of the extremely powerful and cool things you can do with C. I’m not claiming that writing these programs will be easy, or that C is the best fit to write certain kinds of programs. Some are more cumbersome than others, some are more of a stretch than others. But the point is, there’s no limit to C. You might be surprised what can be and what is done with C. It’s not just a language for the basement. It’s a language for the whole software universe.

Disclaimer

When I’m talking about C, I don’t mean C++. While C++ is an extremely powerful language and worth studying on its own right, it’s definitely not C. It’s not even 100% compatible with C. Similarly, it is not a must. Therefore I populated this list excluding C++. The authors of these projects intentionally restricted themselves to C when developing, and occasionally provided a well separated compatibility layer for C++ (and other languages), while continue to develop in C. There’s a reason to do so. C++ can simplify development in certain scenarios, but also can complicate things heavily, and simplicity is often the way to go when effectiveness is key. Or as the designer and original implementer of C++ once phrased:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off. — Bjarne Stroustrup

Robotics

Let’s start with the obvious. C is used heavily for writing embedded software. That expands from Raspberry Pi and Arduino home projects through real-time operating systems to heavy machinery like an airplanes. C is used because it’s the first high level language close to the hardware. Since the kernel is already written in C, you don’t need to look any further to find a programming language to write the rest of your software. C is also the most energy efficient programming language out there, so you probably don’t want to miss it, when developing robots.

Watch out, it can even look cool!

LVGL — The Light and Versatile Graphics Library homepage
Eyecandy for Embedded Software with LVGL

Smart TV anyone?

Did I mention embedded software? I know I did, but when it comes to embedded software we rarely think about wicked cool user interfaces one typically sees when turns on a cutting edge smart TV. Even less so when we discuss software written in C. However this is exactly what you can find in some attractive Samsung devices not restricted to television.

Samsung uses the Enlightenment Foundation Libraries to create user interfaces in their Tizen devices including a refrigerator and a smart watch.

Samsung Q9F Smart TV
Samsung Q9F in Action

You can start developing applications with EFL right now, or even can have a full-featured operating system running Enlightenment to help you cope with your daily tasks.

The Elive Operating System

A Photoshop Alternative

Enlightenment is not the only window manager written in C. The Gnome desktop environment is written almost entirely in C thanks to its own foundation libraries, GTK, which expands to Gimp Toolkit. This latter can be familiar if you ever considered editing some photos, because it’s the first-to-go free alternative to Photoshop.

GIMP’s homepage

You can write applications with very comfortable user interfaces having GTK at your disposal, and it’s portable to effectively any operating system.

At this point you may wonder what does this showcase have to do with the title of ‘How to Write Anything in C’? Well, I have a good news to you. All that I mentioned so far is either free and open source software, or directly supporting development in C with rich documentation, tutorials and howtos. This showcase can serve not only as an inspiration, but also as a starting point to learn more and get a deeper understanding how C is actually used in these environments. If you want to get your hands dirty with code, the code is readily available just a few clicks away from these links.

Windows Applications

Yes, you can develop Windows applications even in JavaScript. But what lesser advertised is that in its core, Microsoft Windows is written in C, and you totally can continue coding in pure C and develop modern Windows applications. Although using the native Windows APIs written in C is not exactly a walk in the park, or even the simplest way to implement things, their higher level abstractions eventually just go back to the underlying layer written in C. Microsoft does everything to hide this layer from the developers, but they don’t deny the fact that it’s still there. If you can read between the lines, they even provide a tutorial to write a complete application in C. OK, the code is actually in C++, but they hardly use any features that defines C++, and if you remove those and replace them with C counterparts, all that is left is pure C code communicating with pure C functions in Windows’ core.

Android Applications

It really shouldn’t come as a surprise, that it’s totally possible to write complete Android apps in C. Google encourages writing apps in C hardly any more than Microsoft does, but they also expose a native development kit (primarily targeting C++), that can be used to develop apps in C from top to bottom. Of course most of such applications are performance critical applications, because nothing can beat C when it comes to speed. This brings us to our next topic:

Games!

Orx — the Portable Game Engine
Orx — the Portable Game Engine

C was ported to everywhere. In fact porting anything starts with porting the C compiler. As soon as we have the C compiler for a system, a whole world opens up. The same applies to writing games. When you can use C libraries, you can use the fastest, battle tested libraries out there. This includes math and physics libraries, but also complete game engines, and of course 2D-3D acceleration with OpenGL and Vulkan. Most certainly many of such games are already written and opensourced, so we’re not restricted to follow tutorials, we can dive into the studying of the code of existing and widely played games.

Run C in the Browser

This entry is not as much of a stretch as it sounds. If you remember Microsoft Silverlight, which ran C# rich client applications in the browser, you can imagine use cases for the same thing written in C. But it’s even better, as it doesn’t require any plugin that the user might or might not install in advance. It turns out that you can compile C code targeting WebAssembly, which will then run in all major browsers out of the box. A complete toolchain called Emscripten also exists to make WebAssembly C developers’ life even easier.

emscripten homepage

Write the Entire Web Application in C

Speaking of web development, there already exists several high quality web application frameworks written in C for C. It often makes sense to expose some APIs of embedded applications. Devices tend to provide web interfaces to their services. It just received even more emphasis with the advent of IoT — the Internet of Things. C is well prepared, capable of running in a light bulb making all kinds of connectivity possible. Also the fastest web servers out there are written in C. If performance is crucial, C delivers without compromises. Just to name a few:

Web servers

Application Frameworks

AI, Machine Learning and Computer Vision

Artificial Intelligence and its companions belong to a heavily developing field. Anytime you have mission critical applications, you’d better choose a programming language that minimizes overhead and latency with its small footprint and incredible performance. Luckily, C also has its own AI, ML, Artificial Neural Network and CV libraries so it keeps you covered on this cutting edge front as well.

Cranium — Portable, header-only ANN library
Cranium — Portable, header-only ANN library

More Awesome Stuff

The applicability of C doesn’t stop here. Graphics, multimedia, cryptography, concurrency and distributed systems — you name it — probably all exists already, humbly waiting for you to discover. Fortunately, there’s a curated list of all this awesomeness, so you only have to visit one page before you disappear in the rabbit hole. Next time you get pissed off of that stuffy C course in your uni, you might want to stop and appreciate that if C was the last programming language you’ve ever learned, you still could develop whatever the heck you want using it, and enjoy its constant support.

Learn more

In case you feel like learning more C, then there are plenty of resources online. The good thing about C is that it doesn’t change often, so you can also rely on books written decades ago to learn the basics. Once you got the foundations, you can turn your attention towards software engineering in C, namely how to manage multiple file projects, get acquainted with build systems, concurrency, debugging, static analysis, and so on. There’s an easy way to do anything, it’s just not always right in front of our eyes. Resources like the ones mentioned above and below can help you turn into the right direction. And never forget to always have fun!

--

--

Viktor Daróczi

A software engineer focusing on the fun part of computing.