C23 programming for everyone | Hackaday


Here’s a history quiz: What architecture did the first C++ compiler target? Of course, this is a trick question. The original C++ compiler – known then as C with Classes – wrote standard C code which you then compiled for whatever your target. This has many advantages since C compilers are everywhere. We are now seeing a similar approach to bringing C23 to the world with Cake. Cake can translate C23 or other versions to C99 which you can then compile with normal compilers.

While the old C++ compiler, cfront, required special steps to compile (since it was built in C++), you can easily create a cake for Windows or Linux. However, it can also be built with emscripten and you can try it yourself in your web browser.

Curious to know what’s new in C23? Well, some old things have been removed and even more have been deprecated. But the really interesting things are the additions which include floating point decimal types, integers with a specified bit size, standard attributes, and many changes involving constants and initialization. You can find a summary at cppreference.com. Sure, a lot of this stuff has been around for a long time in C++ or common compiler extensions, but it brings together a lot of common practice in standard C.

The only other thing to watch out for is that some features are really in the library. Compiling your code isn’t going to help with the differences between the libraries, though many of the changes just add functions that most libraries provide anyway for things like POSIX compliance.

If you don’t want to search for an interesting example, the drop-down list at the top of the browser’s “playground” allows you to choose from many examples. Just press the “Compile To” button, then you can compile the output to see the program run.

The new standard brings some complexity, but still nothing to do with C++. Why use C? Many reasons, not the least of which is that it is energy efficient.


Comments are closed.