Header Ads

C23 Programming for Everyone

Here’s a history quiz: What architecture did the first C++ compiler target? Of course, it is a trick question. The original C++ — known then as C with classes — compiler wrote out standard C code that you then compiled for whatever your target was. This has a lot of advantages since C compilers are everywhere. Now we are seeing a similar approach to bring 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, needed special steps to compile (since it was built using C++), you can build cake for Windows or Linux easily. However, it can also be built with emscripten and you can try it yourself in your web browser.

Curious about what’s new in C23? Well, some old stuff was removed and even more was deprecated. But the really interesting things are the additions which include decimal floating point types, integers with specified bit size, standard attributes, and many changes involving constants and initialization. You can find a summary over on cppreference.com. Of course, many of these things have been around in C++ or in common extensions for compilers for a long time, but this brings a lot of common practice together 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 differences in libraries, although many of the changes are just bringing in functions that most libraries provide any way for things like POSIX compliance.

If you don’t want to dig around for an interesting example, the drop-down box at the top of the browser “playground” lets you pick among many examples. Just press the “Compile To” button and then you can compile the output to see the program execute.

The new standard does bring some complexity, but still nothing like C++. Why use C? Lots of reasons, not the least of which is that it is energy efficient.


No comments