mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Based on proposal #5448. Defining all `Cpp.<builtin_type>` names. Still unsupported types on LP64: `long long`, `unsigned long long` and `long double`. Still unsupported types on LLP64: `long`, `unsigned long` and `long double`. C++ Interop Demo (on LP64): ```c++ // half.h auto Half(long x) -> float; auto PrintLong(long x) -> void; auto PrintFloat(float x) -> void; ``` ```c++ // half.cpp #include <cstdio> auto Half(long x) -> float { return static_cast<float>(x) / 2; } auto PrintLong(long x) -> void { printf("%ld\n", x); } auto PrintFloat(float x) -> void { printf("%f\n", x); } ``` ```carbon // main.carbon library "Main"; import Cpp library "half.h"; fn Run() -> i32 { let x: Cpp.long = 5; Cpp.PrintLong(x); let y: Cpp.float = Cpp.Half(x); Cpp.PrintFloat(y); return 0; } ``` ```shell $ clang -c half.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link half.o main.o --output=demo $ ./demo 5 2.500000 ``` Part of #5263.