mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:30:14 +01:00
Based on #5920. Added commented out better examples and clarified what is missing to support them. Added `tags` support to `carbon_binary` (based on #5967) to set the `BUILD` rule to manual until we can find `cstdio` in macos. ```shell $ bazel run examples/interop/cpp:hello_world ... Hello world! ```
34 lines
1.0 KiB
Plaintext
34 lines
1.0 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
import Cpp inline "#include <cstdio>";
|
|
|
|
fn Run() {
|
|
// TODO: Requires operator <<, declaration type Var (cout) and class with
|
|
// virtual bases (basic_ostream).
|
|
// Cpp.std.cout << "Hello world!\n";
|
|
|
|
// TODO: Requires variadic function.
|
|
// Cpp.printf("Hello world!\n");
|
|
|
|
// TODO: Requires nullable pointer.
|
|
// Cpp.puts("Hello world!\n");
|
|
|
|
// TODO: Requires nullable void pointer.
|
|
// Cpp.write(1, "Hello world!\n", 13);
|
|
|
|
// TODO: Requires Core.String API.
|
|
// let message: str = "Hello world!\n\n";
|
|
// for (c: Core.Char in msg) {
|
|
// Cpp.putchar((c as u8) as i32);
|
|
// }
|
|
|
|
let message: array(Core.Char, 13) =
|
|
('H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n');
|
|
for (c: Core.Char in message) {
|
|
// TODO: u8 should probably have an implicit cast to i32.
|
|
Cpp.putchar((c as u8) as i32);
|
|
}
|
|
}
|