mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 22:02:37 +01:00
Added support for `int` function parameters. Currently only
pass-by-value is supported.
```c++
// hello_int.h;
auto foo_int(int a, int b) -> int;
```
```c++
// hello_int.cpp
#include "hello_int.h"
#include <cstdio>
auto foo_int(int a, int b) -> int {
printf("a = %i \n", a);
printf("b = %i \n", b);
return a + b;
}
```
```c++
// main.carbon
library "Main";
import Cpp library "hello_int.h";
import Core library "io";
fn Carbon_foo(b: i32) {
Core.Print(b);
}
fn Run() -> i32 {
Carbon_foo(Cpp.foo_int(2, 8));
return 0;
}
```
```
$ clang -c hello_int.cpp
$ bazel-bin/toolchain/carbon compile main.carbon
$ bazel-bin/toolchain/carbon link hello_int.o main.o --output=demo
$ ./demo
a = 2
b = 8
10
```
Part of #5064