|
|
4 tahun lalu | |
|---|---|---|
| .. | ||
| README.md | 05efb278c2 as expressions (#845) | 4 tahun lalu |
| as_expressions.md | b7df523dc8 Fix cross-file links in non-proposal files (#1010) | 4 tahun lalu |
| implicit_conversions.md | b7df523dc8 Fix cross-file links in non-proposal files (#1010) | 4 tahun lalu |
Expressions are the portions of Carbon syntax that produce values. Because types in Carbon are values, this includes anywhere that a type is specified.
fn Foo(a: i32*) -> i32 {
return *a;
}
Here, the parameter type i32*, the return type i32, and the operand *a of
the return statement are all expressions.
When an expression appears in a context in which an expression of a specific type is expected, implicit conversions are applied to convert the expression to the target type.
Expressions can also be converted to a specific type using an
as expression.
fn Bar(n: i32);
fn Baz(n: i64) {
// OK, same as Bar(n as i32)
Bar(n);
}