Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

C3

< >

C3 is an open source programming language created in 2019 by Christoffer LernΓΆ.

#154on PLDB 5Years Old
Download source code:
git clone https://github.com/c3lang/c3c
Homepage Β· Source Code Β· Blog Β· Twitter

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.


Example from the web:
module stack <Type>; // Above: the parameterized type is applied to the entire module. import std::mem; struct Stack { usize capacity; usize 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; this.elems = mem::realloc(this.elems, $sizeof(Type) * 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; }

Language features

Feature Supported Example Token
hasReservedWords βœ“
Switch Statements βœ“ switch(expression) { case 1: do_something(); case 2: if (x > 0) nextcase 1; // Jump to 1 nextcase; // Jump to the next case. default: foo(); }
Structs βœ“ struct Test { int x; float y; String z; }
Strings βœ“ String s = "hello"; String t = `I say "hello"`;
Ternary operators βœ“ int foo = x ? 1 : 0;
Scientific Notation βœ“
While Loops βœ“ while (int x = foo(); x > 0) { sum += x; }
Conditionals βœ“
Assignment βœ“ a = b;
Case Sensitivity βœ“
Pointers βœ“
Variadic Functions βœ“ fn void foo_typed(int x, int... arg) { ... } fn void foo_untyped(int x, ...arg) ... foo_typed(1, 2, 3); foo_untyped(1, "hello", 1.2);
Module Pattern βœ“ module my_module::submodule; ...
Operator Overloading βœ“ fn int IntList.get(IntList* this, int idx) @operator([]) { return this.vals[idx]; } ... IntList x = ... foo(x[1]);
Multiline Strings βœ“ String s = `this string is multiline`;
MultiLine Comments βœ“ /* Multiline comment */ /* */
Methods βœ“ fn int Foo.get_value(Foo* this) { return this.value; }
File Imports βœ“ import std::io;
hasForEachLoops βœ“ foreach (x : list) { foo(x); }
Macros βœ“ macro square(x) { return x * x; }
Union Types βœ“ union Foo { int x; float f; struct { char[2] z; } }
Single-Type Arrays βœ“
Unary Operators βœ“
Enums βœ“ enum TestEnum : int { FOO, BAR, BAZ }
Doc comments βœ“ /** * @param [in] foo "The foo value" * @return "the toal foo count" **/
Constants βœ“ const FOO = 123; const void* BAR = null;
Access Modifiers βœ“
Zero-based numbering βœ“
Default Parameters Pattern βœ“ fn void test(int x = 10) { ... }
Assert Statements βœ“ assert(a > 0, "Expected a positive number"); $assert(Foo.sizeof == 8, "Foo sizecheck at compile time failed");
Manual Memory Management βœ“
Increment and decrement operators βœ“ i++; --j;
Integers βœ“ int x = 314159;
Namespaces βœ“ import std::io; ... io::printf("%d", i);
Type Casting βœ“ double d = 3.3; int x = (int)d;
Binary Literals βœ“ 51
Null βœ“
Lazy Evaluation βœ“ fn void print(String s) { io::printfn("Said: %s", s); } macro @foo(bool run, #lazy) { if (run) #lazy; } // Only "Said: Hello" is printed: @foo(false, print("Bye")); @foo(true, print("Hello"));
Labels βœ“ while FOO: (x > 0) { for (int i = 0; i < 10; i++ { x = baz(); if (x > i) break FOO; } }
Inheritance βœ“
Functions βœ“
Implicit Type Casting βœ“
hasIfElses βœ“
hasIfs βœ“
Hexadecimals βœ“
hasForLoops βœ“
Expressions βœ“
hasEscapeCharacters βœ“ "\e\n\r"
hasContinue βœ“
hasBreak βœ“
hasBoundedCheckedArrays βœ“
hasArraySlicingSyntax βœ“ int[] slice1 = array[0..5]; // start..end int[] slice2 = array[0:6]; // start:length
Octals βœ“ 127
Bitwise Operators βœ“ int i = b << 4 + x; // Same as (b << 4) + x
Booleans βœ“ true false
Comments βœ“ // A comment /* Another comment */
Line Comments βœ“ // A comment //
Garbage Collection X
Gotos X
Case Insensitive Identifiers X
Constructors X
Variable Substitution Syntax X
hasUserDefinedOperators X
Units of Measure X
Unicode Identifers X
Abstract Types X
Classes X
Directives X
Multiple Inheritance X
S-Expressions X
Pipes X
Message Passing X
Magic Getters and Setters X
Homoiconicity X
Function Composition X
Function Overloading X
Here Document X
Dynamic Properties X
Duck Typing X
hasBuiltInRegex X
Async Await X
Semantic Indentation X
Regular Expression Syntax Sugar X

- Build the next great programming language Β· Add Β· About Β· Search Β· Keywords Β· Livestreams Β· Labs Β· Resources Β· Acknowledgements

Built with Scroll v144.0.0