SkillAgentSearch skills...

C3c

Compiler for the C3 language

Install / Use

/learn @c3lang/C3c
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

C3 Language

C3 is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers.

It's an evolution, not a revolution: the C-like for programmers who like C.

Precompiled binaries for the following operating systems are available:

The manual for C3 can be found at www.c3-lang.org.

vkQuake

Thanks to full ABI compatibility with C, it's possible to mix C and C3 in the same project with no effort. As a demonstration, vkQuake was compiled with a small portion of the code converted to C3 and compiled with the c3c compiler. (The aging fork can be found at https://github.com/c3lang/vkQuake)

A non-curated list of user written projects and other resources can be found here.

Design Principles

  • Procedural "get things done"-type of language.
  • Try to stay close to C - only change what's really necessary.
  • C ABI compatibility and excellent C integration.
  • Learning C3 should be easy for a C programmer.
  • Data is inert.
  • Avoid "big ideas" & the "more is better" fallacy.
  • Introduce some higher level conveniences where the value is great.

C3 owes its inspiration to the C2 language: to iterate on top of C without trying to be a whole new language.

Example code

The following code shows generics (more examples can be found at https://c3-lang.org/language-overview/examples/).

module stack <Type>;
// Above: the parameterized type is applied to the entire module.

struct Stack
{
    usz capacity;
    usz size;
    Type* elems;
}

// The type methods offers dot syntax calls,
// so this function can either be called
// Stack.push(&my_stack, ...) or
// my_stack.push(...)
fn void Stack.push(Stack* this, Type element)
{
    if (this.capacity == this.size)
    {
        this.capacity *= 2;
        if (this.capacity < 16) this.capacity = 16;
        this.elems = realloc(this.elems, Type.sizeof * this.capacity);
    }
    this.elems[this.size++] = element;
}

fn Type Stack.pop(Stack* this)
{
    assert(this.size > 0);
    return this.elems[--this.size];
}

fn bool Stack.empty(Stack* this)
{
    return !this.size;
}

Testing it out:

import stack;

// Define our new types, the first will implicitly create
// a complete copy of the entire Stack module with "Type" set to "int"
alias IntStack = Stack {int};
// The second creates another copy with "Type" set to "double"
alias DoubleStack = Stack {double};

// If we had added "alias IntStack2 = Stack {int}"
// no additional copy would have been made (since we already
// have an parameterization of Stack {int} so it would
// be same as declaring IntStack2 an alias of IntStack

// Importing an external C function is straightforward
// here is an example of importing libc's printf:
extern fn int printf(char* format, ...);

fn void main()
{
    IntStack stack;
    // Note that C3 uses zero initialization by default
    // so the above is equivalent to IntStack stack = {};

    stack.push(1);
    // The above can also be written IntStack.push(&stack, 1);

    stack.push(2);

    // Prints pop: 2
    printf("pop: %d\n", stack.pop());
    // Prints pop: 1
    printf("pop: %d\n", stack.pop());

    DoubleStack dstack;
    dstack.push(2.3);
    dstack.push(3.141);
    dstack.push(1.1235);
    // Prints pop: 1.123500
    printf("pop: %f\n", dstack.pop());
}

In what ways does C3 differ from C?

  • No mandatory header files
  • New semantic macro system
  • Module based name spacing
  • Slices
  • Operator overloading
  • Compile time reflection
  • Enhanced compile time execution
  • Generics based on generic modules
  • "Result"-based zero overhead error handling
  • Defer
  • Value methods
  • Associated enum data
  • No preprocessor
  • Less undefined behaviour and added runtime checks in "safe" mode
  • Limited operator overloading to enable userland dynamic arrays
  • Optional pre and post conditions

Current status

The current stable version of the compiler is version 0.7.11.

The upcoming 0.7.x releases will focus on expanding the standard library, fixing bugs and improving compile time analysis. Follow the issues here.

If you have suggestions on how to improve the language, either file an issue or discuss C3 on its dedicated Discord: https://discord.gg/qN76R87.

The compiler is currently verified to compile on Linux, OpenBSD, Windows and MacOS.

Support matrix

| Platform | Native C3 compiler available? | Target supported | Stack trace | Threads | Sockets | Inline asm | |--------------------------|-------------------------------|-------------------------|-------------|----------|----------|------------| | Win32 x64 | Yes | Yes + cross compilation | Yes | Yes | Yes | Yes* | | Win32 Aarch64 | Untested | Untested | Untested | Untested | Untested | Yes* | | MacOS x64 | Yes | Yes + cross compilation | Yes | Yes | Yes | Yes* | | MacOS Aarch64 | Yes | Yes + cross compilation | Yes | Yes | Yes | Yes* | | iOS Aarch64 | No | Untested | Untested | Yes | Yes | Yes* | | Android Aarch64 | No | Untested | Untested | Untested | Untested | Yes* | | Android x64 | No | Untested | Untested | Untested | Untested | Yes* | | Linux x86 | Yes | Yes | Yes | Yes | Yes | Yes* | | Linux x64 | Yes | Yes | Yes | Yes | Yes | Yes* | | Linux Aarch64 | Yes | Yes | Yes | Yes | Yes | Yes* | | Linux Riscv32 | Yes | Yes | Yes | Yes | Yes | Untested | | Linux Riscv64 | Yes | Yes | Yes | Yes | Yes | Untested | | ELF freestanding x86 | No | Untested | No | No | No | Yes* | | ELF freestanding x64 | No | Untested | No | No | No | Yes* | | ELF freestanding Aarch64 | No | Untested | No | No | No | Yes* | | ELF freestanding Riscv64 | No | Untested | No | No | No | Untested | | ELF freestanding Riscv32 | No | Untested | No | No | No | Untested | | ELF freestanding Xtensa* | No | Untested | No | No | No | Untested | | FreeBSD x86 | Untested | Untested | No | Yes | Untested | Yes* | | FreeBSD x64 | Untested | Untested | No | Yes | Untested | Yes* | | NetBSD x86 | Untested | Untested | No | Yes | Untested | Yes* | | NetBSD x64 | Untested | Untested | No | Yes | Untested | Yes* | | OpenBSD x86 | Untested | Untested | No | Yes | Untested | Yes* | | OpenBSD x64 | Yes* | Yes | Yes* | Yes | Untested | Yes* | | MCU x86 | No | Untested | No | No | No | Yes* | | Wasm32 | No | Yes | No | No | No | No | | Wasm64 | No | Untested | No | No | No | No |

* Inline asm is still a work in progress<br> * OpenBSD 7.7 is the only tested version<br> * OpenBSD has limited stacktrace, needs to be tested further<br> * Xtensa support is enabled by compiling with -DXTENSA_ENABLE. The espressif llvm fork is recommended for best compatibility

More platforms will be supported in the future.

What can y

Related Skills

View on GitHub
GitHub Stars5.3k
CategoryDevelopment
Updated15h ago
Forks353

Languages

C3

Security Score

100/100

Audited on Apr 3, 2026

No findings