Home | Manual | Static Analysis | Playground

Cake - C23 and Beyond

Kernighan & Ritchie, The C Programming Language, 1978:

"C is a general-purpose programming language which features economy of expression, modern control flow and data structures, and a rich set of operators. C is not a "very high level" language, nor a "big" one, and is not specialized to any particular area of application. But its absence of restrictions and its generality make it more convenient and effective for many tasks than supposedly more powerful languages."

"In our experience, C has proven to be a pleasant, expressive, and versatile language for a wide variety of programs. It is easy to learn, and it wears well as one's experience with it grows"

Kernighan & Ritchie, The C Programming Language, Second Edition, 1988:

"As we said in the preface to the first edition, C "wears well as one's experience with it grows." With a decade more experience, we still feel that way."

C is everywhere. From operating systems to embedded devices, from high-performance apps to essential technology, C powers the technology we rely on every day. Timeless, efficient, and universal.

The code that AI now writes runs best where it can be read, verified and trusted. A small language with no hidden machinery. C gives the machine speed, and the human control and platform independence. Cake adds the checks that make that code safer.

About

Cake is a compiler front end written from scratch in C by a human, implementing the C23 language specification and beyond.

It serves as a platform for experimenting with new features, including C2Y language proposals, safety enhancements, and extensions such as literal functions and defer statements.

The current backend generates C89-compatible code, which can be pipelined with existing or old compilers to produce executables.

Cake pipeline: C23 source to C89 output to an existing compiler

Cake aims to enhance C's safety by providing high-quality warning messages and advanced flow analysis, including object lifetime checks.

Web Playground

This is the best way to try it.

https://cakecc.org/playground.html

Use cases

Note: Cake is still in development and has not yet reached a stable version.

Cake can be used as a static analyzer alongside other compilers. It generates SARIF files, which are recognized by popular IDEs such as Visual Studio and Visual Studio Code, providing a seamless integration.

It can also function as a preprocessor, converting C23 code to C89. This allows developers to use modern or experimental features while targeting compilers that do not yet support the latest language standards.

Cake is also a cross-compiler. For example, on Windows it can use Linux headers and generate GCC-compatible code for Linux, and vice versa. This makes it very useful when developing multiplatform code.

Another use of Cake is as a library to parse source code and build an AST, which can then be used for other purposes; for instance, automatic serialization, automatic documentation and more.

Features

Build

GitHub https://github.com/thradams/cake

MSVC build instructions

Open the Developer Command Prompt of Visual Studio. Go to the src directory and type

cl build.c && build

This will build cake.exe, then run cake on its own source code.

GCC on Linux build instructions

Go to the src directory and type:

gcc build.c -o build && ./build

Clang on Linux/Windows/macOS build instructions

Go to the src directory and type:

clang build.c -o build && ./build

If you encounter an error such as: fatal error: X11/Xft/Xft.h: No such file or directory

Ubuntu / Debian: sudo apt install libx11-dev libxft-dev

Fedora: sudo dnf install libX11-devel libXft-devel

Arch Linux: sudo pacman -S libx11 libxft

openSUSE:sudo zypper install libX11-devel libXft-devel

These headers are used by the IDE.

Build options

build accepts one optional argument, on any platform:

Argument Effect
(none) full build: tools, docs, amalgamated lib.c, cake and the IDE
fast incremental build of cake and the IDE only — skips tools, docs, inner tests and the amalgamation
full build everything with -DTEST, but do not run the test suite
test same as full, then run the test suite
debug build without optimizations and without -DNDEBUG

For example, to run the tests:

gcc build.c -o build && ./build test

Emscripten build instructions (web)

Emscripten is required.

First do the normal build: besides cake, it generates lib.c, the amalgamated version of the core library, which is what the web build compiles.

Then, in the src directory, type:

emcc -sSTACK_SIZE=8388608 -DMOCKFILES -Wno-multichar lib.c -o web/cakejs.js -s WASM=0 -s EXPORTED_FUNCTIONS="['_CompileText']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap']"

This generates src/web/cakejs.js, used by src/web/playground.html.

Installation (optional)

Installation is optional. Cake can be built and run directly from the src directory as shown above, without installing anything. Installing simply copies the compiler and supporting files into a system directory and updates the system PATH so the cake command can be executed from any terminal.

Windows

Run the installer as Administrator.

install.exe

The installer:

Linux / macOS

Run the installer using:

sudo ./install

The installer:

Changes become available in new login sessions.

Running cake

cake source.c

This writes the C89 output to ./<target>/source.c, where <target> is the platform Cake was built for — for example ./macos_arm64/source.c or ./x64_msvc/source.c. -target=<name> selects another platform; see the Manual for the full option list.

IDE

The Cake IDE was developed with the help of AI tools. It has now been adopted as part of the Cake project and will be maintained alongside the rest of the codebase. Over time, the IDE code will be reviewed, refined, and gradually humanized as the project evolves.

The IDE works in macOS, Windows and Linux. Its purpose is to make Cake easier to use: open a file or a project, press Build, and the whole pipeline — Cake's C89 output, the external compiler, the debugger — is set up and driven from one place, with no command lines to remember. It is very useful to visualize and remove warnings: Cake's diagnostics show up in the Output window and jump straight to the offending line.

It is also how Cake itself is developed and debugged. The src/cakeprj.cakeproj project builds the compiler with the same process any other project uses: Cake translates the sources to C89, an External Tool (gcc, clang or cl) links the generated code, and the built-in debugger (lldb / cdb) runs the result. Opening that project is the quickest way to step through the compiler while it compiles a sample.

See IDE Manual

Cake IDE

Road map

Participating

You can contribute by trying out cake, reporting bugs, and giving feedback.

Have a suggestion for C?

DISCORD SERVER

https://discord.gg/YRekr2N65S

Cake x CFront

CFront was the first C++ compiler, designed to translate C++ source code into C. Initially compatible with C89, it diverged as the C and C++ languages evolved independently.

Cake maintains alignment with the standard specifications and ongoing development of C, ensuring full compatibility.

The compiler introduces extensions that preserve the fundamental design of C while supporting experimentation and open contributions to the language's evolution.

License

Cake uses the same license as GCC: GPLv3.