hello_world.carbon 978 B

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. import Cpp inline "#include <cstdio>";
  5. fn Run() {
  6. // TODO: Requires class with virtual bases (`basic_ostream`).
  7. // Cpp.std.cout << "Hello world!\n";
  8. // TODO: Requires variadic function.
  9. // Cpp.printf("Hello world!\n");
  10. // TODO: Requires nullable pointer.
  11. // Cpp.puts("Hello world!\n");
  12. // TODO: Requires nullable void pointer.
  13. // Cpp.write(1, "Hello world!\n", 13);
  14. // TODO: Requires Core.String API.
  15. // let message: str = "Hello world!\n\n";
  16. // for (c: char in message) {
  17. // Cpp.putchar((c as u8) as i32);
  18. // }
  19. let message: array(char, 13) =
  20. ('H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n');
  21. for (c: char in message) {
  22. // TODO: u8 should probably have an implicit cast to i32.
  23. Cpp.putchar((c as u8) as i32);
  24. }
  25. }