Functions and declarations in NanoC
Zero-argument functions can omit parentheses: f get i32. Parameters are always name-first: f clamp(x,lo,hi: i32) i32, or f mix(x: i32, y: f64). Bare parameter names inherit the following type. The optional return type follows the name or parameter list directly: void by default, i32 for main. The final value expression in a non-void function returns automatically, including final if/elif/else branches. Use < value for an early return and < for a void return. End an expression with a semicolon to make it a statement instead. Declarations, assignments, loops and directives do not become implicit results. A semicolon after a function header declares a prototype.
f add(a: i32, b: i32) i32
< a+b
f greet()
<
f main()
n := 2
result: i32 = add(n,3)
greet()
< result != 5int add(int a, int b) {
return a+b;
}
void greet(void) {
return;
}
int main(void) {
int n = 2;
int result = add(n,3);
greet();
return result != 5;
}:= infers scalar literals. Calls, arithmetic, names and array literals require an explicit type: write name: type = value, and nums: i32[] = {1,2,3} for arrays. Wrap complex C declarators in backticks. Integer literal inference uses int for the guaranteed signed 16-bit range, long for the guaranteed signed 32-bit range, and long long outside it in C99 onward. Floating literals infer double and C character literals infer int. C++17 additionally permits auto inference. No typeof extension is emitted. No short type aliases are provided; use C types or typedefs from headers.