Statements
- The semicolon at the end of a statement can be omitted.
- No
do while
orgoto
(otherwise same as C++) switch
doesn't fall through by default (usefallthrough
explicitly)
switch (i) {
case 1:
fallthrough
case 2:
printf("%d\n", i)
}
Unsafe
Dereference raw pointers in unsafe blocks:
var p: *Int
...
unsafe {
var i = *p
}
Unsafe functions require unsafe blocks:
unsafe fun foo() { ... }
fun main() {
unsafe {
foo()
}
}
Expressions
Operator precedence matches C/C++ except bitwise operators have higher precedence than comparisons
if (i & Mask != 0) {}
// Equivalent to:
if ((i & Mask) != 0) {}
Only prefix ++i is supported (no postfix i++)
With Blocks
With blocks (unlike C++ designated initializers) can contain any statements:
struct A {
var i: Int
fun init() { ... }
}
var a = A { .init(); .i = 0 }
var a: own* A = new A { .i = 0 }
Pointer Access
Use . for both direct and pointer access (no ->):
var a: A
var b: own* A
a.foo()
b.foo()
Type Conversion/Checking
as for dynamic/numeric conversion, is for type checking:
var a = p as own* A
var b = p is own* A
Other conversions use unsafeCast.
Error Handling
Since Sric does not support exception handling, Optional can serve as an alternative for error return.