Skip to content

Function Declarations

Overview

Function declarations provide a name and signature for logic units. A bare function name used in an expression context evaluates to a function pointer value.

Syntax

function someFunction(a: int, b: int): int {
    return a + b;
}

extern function externalFunction(a: int): int;

Rules

Parameter Types

All function parameters MUST be explicitly typed.

Return Types

If the function returns a value, the return type MUST be explicitly specified. If the return type annotation is omitted, the function MUST return no value.

Visibility

The export qualifier MUST be supported for function declarations to make them visible to other compilation units. Functions without the export qualifier MUST NOT be externally linkable.

Extern Functions

The extern qualifier MUST be supported for function declarations. Function declarations with the extern qualifier MUST provide a name and signature without a body; a function body on an extern declaration MUST NOT be permitted. Linkage for extern functions is implementation-defined. Functions with the extern qualifier combined with the export qualifier to make them visible to other compilation units MUST be permitted.

Function Locality

Function declarations MUST only appear at the top level of a compilation unit. Nested function declarations MUST NOT be permitted.

Function Uniqueness

Duplicate function names within the same compilation unit MUST NOT be permitted. Name uniqueness across compilation units is implementation-defined.