Carbon is an experimental programming language designed for interoperability with C++. The project is open-source and was started at Google. Google's engineer Chandler Carruth first introduced Carbon at the CppNorth conference in Toronto in July 2022. He stated that Carbon was created to be a C++ successor. The language is expected to have an experimental minimum viable product (MVP) version 0.1 in late 2026 at the earliest and a production-ready version 1.0 after 2028.

The language intends to fix several perceived shortcomings of C++ but otherwise provides a similar feature set. The main goals of the language are readability and "bi-directional interoperability" (which allows the user to include C++ code in the Carbon file), as opposed to using a new language like Rust, that, while being influenced by C++, is not two-way compatible with C++ programs. Changes to the language will be decided by the Carbon leads. It aims to build on the C++ ecosystem the way in an analogous role to TypeScript on JavaScript, or Kotlin on Java.

Carbon's documents, design, implementation, and related tools are hosted on GitHub under the Apache 2.0 license with LLVM Exceptions.

Example

The following shows how a program might be written in Carbon and C++:

CarbonC++
packageGeometry; importMath; classCircle{ varradius:f32; } fnPrintTotalArea(circles:[Circle]){ vararea:f32=0; for(circ:Circleincircles){ area+=Math.Pi*circ.radius*circ.radius; } Print("Total area: {0}",area); } fnRun()->i32{ // A dynamically sized array, like `std::vector`. varcircles:array[Circle]=({.radius=1.0},{.radius=2.0}); // Implicitly constructs a slice from the array. PrintTotalArea(circles); return0; }importstd; usingstd::span; usingstd::vector; structCircle{ floatradius; }; voidprintTotalArea(span<Circle>circles){ floatarea=0.0f; for(constCircle&circ:circles){ area+=std::numbers::pi*circ.radius*circ.radius; } std::println("Total area: {}",area); } intmain(intargc,char*argv[]){ vector<Circle>circles{{.radius=1.0f},{.radius=2.0f}}; // Implicitly converts `vector` to `span`. printTotalArea(circles); return0; }

See also

External links