BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News C2 Aims to Modernize the C Language

C2 Aims to Modernize the C Language

This item in japanese

Bookmarks

C2 is a new programming language aiming to be an evolution of C that is suitable for low-level programs like bootloaders, kernels, drivers, and system-level tooling.

C2’s mission statement is keeping the good parts of C while changing those parts that betray it being a 40-year old language, says its creator Bas van den Berg. Undesirable aspects of C include the use of header files, which greatly slow the compiler down, and complex type declaration syntax, which C2 replaces with a module system and its uniform type syntax. C2 also introduces an integrated build system supporting full link-time optimization (LTO), while a macro system is in the works.

This is how a prototypical "hello world" program looks like in C2, showcasing modules and imports, and the type system:

module hello_world;

import stdio as io;

func i32 main(i32 argc, char*[] argv) {
    io.printf("Hello World!\n");
    return 0;
}

C2 does not aim to add higher-level features such as OO-support and garbage collection.

InfoQ has spoken with Bas van den Berg, creator of the language.

InfoQ: What are the main goals of C2?

Bas van den Berg: I’ve been working with C for almost 20 years now. In that time I’ve used it to write/ modify drivers, low-level/high-performance applications, real-time systems, etc. So stuff you typically use C for. I really like C, but some things are showing their age. Since I don’t see any other languages invading that part of the C-domain (e.g., low-level, kernels etc.) and I didn’t want to spend another 20 years solving the same issues again and again, I started C2. So the main goal of C2 is to solve the common issues with C and improve the developer experience.

InfoQ: Do you envision the possibility for existing C code bases to be migrated to C2? Would that provide some advantage?

van den Berg: Since C programs almost never work stand-alone but use other (C) libraries, the same goes for C2. So C2 programs need to be able to easily use C libraries and also C libraries need to be able to integrate with C2 libraries as well. As a demo I’ve ‘ported’ the Lua and Vulkan interfaces within a few days to C2. There is a demo implementation in the c2_examples that show how this works. What I personally do to get a feel for C2 is to port programs in C to C2 to see if there are any nasty issues. If there are, these are fixed in C2. This way the syntax evolves. The advantage of porting a current C program would be easier access to full program optimization, much faster compile times.

InfoQ: What is the current maturity status of the language and its tooling? When do you foresee it could be production-ready?

van den Berg: In its current form, I wouldn’t advice using C2 for production code, but for smaller projects, it’s definitely usable. Since the syntax is not yet frozen, any update might however break your program.

Two areas where C2 will change is the addition of the macro subsystem (still in design) and the library subsystem will be expanded to allow source-libraries and a Cargo-like tool to manage external packages. I’m currently working on the library system and that should be gradually released in Q2 this year. The macro subsystem is planned after that.

According to van den Berg’s own experience, the use of C2 can speed up development by 30%. C2 is open source and can be installed on Linux, macOS, and Windows.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • C2 is GO-- ?

    by Sai Matam,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    There has been a resurgence in the low-level languages. Rust, Go and now I heard about C2. Each of these languages is experimenting its own unique flavor of syntax and features. Go programming language has garbage collection whereas C2 does not. The multiple approaches and the experimentation will lead to better programming languages and, hopefully, better and more robust code.


    --Sai Matam

    Enablor, Inc.

  • Re: C2 is GO-- ?

    by Sergio De Simone,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    That's an interesting point -- and it matches with a prediction that Alex Payne made a few years ago about the future of programming languages saying that we were going to see a renewed interest in native languages.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT