Back to C²
Arise, my child!
Welcome back to my lair! Recently I’ve revived a project that some may know: C².
C² is a superset of C, designed as basically a nicer-to-use C version.
Some of the features/changes it has compared to C:
These are planned.
- Built-in error types (Zig-like) with
errorunions andvoid!-like (voidcan be any type) function return types. - Namespaces (not like C++).
- Better enums based in
enum classfrom C++, as C’s enums declare global constants that can collide in name, meaning most C programs must use some prefix for the enum, which is much less nice than just usingMyEnum.WhateverinsteadMyEnum_Whateveras a constant. - Completely structural typing where field names don’t matter and types must only have fields/items of the same type to be considered compatible.
- Better include system that ditches headers for a module-based approach.
- Better memory management that ditches raw
mallocs andfreefor allocator structures, built-in keyword-based freeing (freekeyword) anddeferfor automatic end-of-block cleanup. - More types quadruple-precision floats1, built-in from day one booleans
(C got booleans pretty late as
_Boolin C99, and there are still programs that use<stdbool.h>for booleans orintdirectly). - Safer types by being more strict with casts, forcing uncasted values to be
the exact same type (meaning that you can’t assign an
uintto anulongwitho ut casting) and clearer type-specific literals (100.0ffor floats,100ufor unsigned integers of any size, etc.). - VM-based for faster iteration, packages supported and you can create binaries out of the runtime + the bytecode.
What is implemented right now #
For now, I’ve made a lexer that runs pretty fast (100k iterations in ~44μs, or
~0.000044 seconds), an error printing system:
and a test suite:
Right now I am working in the parser, which will be probably finished soon and I will start with the real deal: compilation!.
Links #
some nicher although existing programs, such as fractal generation, some cryptography algorithms, etc. require 128-bit precision floats (
_Float128in C, which is a GCC extension). C² will include them by default as thequadtype with it’s own literal100.0q(and in exponential notation100.0e1q). ↩︎