Skip to content

Compile-Time Constants

Overview

intdef and typedef provide compile-time integer constants and type aliases respectively.

Syntax

intdef MAX_SIZE 100;
intdef MIN_SIZE 0;
intdef MAX_UINT 0xFFFFFFFFu;
intdef NEG_ONE -1;
typedef IntArray []int;
export intdef EXPORTED_SIZE 64;
export typedef ExportedArray []int;

Rules

Intdef Substitution

intdef values MUST be substituted at compile-time and MUST NOT occupy memory at runtime.

Intdef Value Constraints

An intdef value MUST be an integer literal in decimal or hexadecimal form. A unary minus - MUST be permitted to indicate a negative value. The u or U suffix MUST be permitted to indicate an unsigned value. A unary minus and the u/U suffix MUST NOT be permitted for use on the same intdef.

Intdef Type

The type of an intdef MUST be int by default, or uint if the u/U suffix is present. A value that overflows the range of its type MUST be a compile-time error.

Typedef Alias Resolution

typedef aliases MUST be resolved to their underlying types at compile-time. Circular or recursive typedef declarations MUST NOT be permitted.

Typedef and Forward-Declared Structs

A typedef MUST be permitted to alias a forward-declared struct. The alias MUST maintain the semantics of the forward-declared struct; operations requiring the struct's layout MUST NOT be permitted through the alias until the full definition is provided.

Scope

intdef and typedef declarations MUST only be allowed to appear at the top level of a compilation unit.

Visibility

The export qualifier MUST be supported for intdef and typedef declarations. Exported declarations MUST be included in the compilation unit's generated metadata, making them available to dependent compilation units. Declarations without the export qualifier MUST NOT be included in the generated metadata.