Cesium logo Cesium

Variables and Constants

November 22, 2026

Basic Declaration

// Basic declaration with initialization
i32 count = 0;
f64 pi = 3.14159;

Constant Variables

// Constant variables
const i32 MAX_SIZE = 1000;
const str VERSION = "1.0.0";

Pointer Declaration

Ownership and borrowing apply to pointers only. A pointer is given its address with one of three address-context operators, never with plain =:

i32 count = 0;
i32 total = 0;

#i32 reader #= #count;              // immutable borrow of a plain value
~i32 writer ~= ~total;              // mutable borrow of a plain value
~Matrix m := create_matrix(3, 3);   // owner: takes ownership of what the function returns
defer free(m);

writer = 5;                         // plain = assigns through the pointer: total is now 5

:= is only meaningful with a pointer on the left; Matrix m := create_matrix(3, 3); is a compile error. See Memory Management for the full rules.

Uninitialized Variables

u8 x;                 // declared, not initialized
~Buffer buf;          // a pointer that owns nothing yet (undefined)

Question: Open

Whether a pointer that owns nothing may be declared bare, as on the last line, or must be written out with undefined, and how undefined is written for a plain value, are being discussed in cesiumlang/cesium#25.

undefined is a keyword. For a plain value it means truly uninitialized. For a pointer it is a defined “owns nothing” state, distinct from null, and there is no test for it.

Storage and Access Qualifiers

// Storage and access qualifiers
static i32 global_counter = 0;    // function-scoped persistence
private void = helper();          // module-internal function
secret i32 internal_state;       // class-internal only

Hardware Qualifiers

// Hardware qualifiers
volatile u32 hardware_register;   // prevent optimization
atomic u64 shared_counter;        // thread-safe operations
register u64 hot_variable;        // register allocation hint

Qualifier Descriptions

QualifierDescription
constValue cannot be modified after initialization
staticVariable persists between function calls
privateAccessible only within the current module
secretAccessible only within the current class/struct
volatilePrevents compiler optimizations
atomicEnsures thread-safe operations
registerSuggests register allocation
simdEnables SIMD vectorization

Assignment Operators

OperatorLeft sideMeaning
=plain valuecopies the value
=pointerassigns through the pointer (the pointer is dereferenced)
#=#T pointerimmutable borrow: points the pointer at an address, read-only
~=~T pointermutable borrow: points the pointer at an address, read-write
:=#T or ~T pointertakes ownership of the memory at an address

The sigil in the type and the operator must agree: ~T p #= q; and #T p ~= q; are compile errors.

~Matrix original := create_matrix(3, 3);
~Matrix moved := original;          // ownership transferred; original can no longer be used
~Matrix other := create_matrix(3, 3);

#Matrix borrowed #= moved;          // immutable borrow
~Matrix mut_borrowed ~= other;      // mutable borrow

// ... and once the borrows are no longer in use:
free(moved);
free(other);

Question: Open

What = does to a plain value that owns memory (a str, a list, or a struct with owning fields) is not decided: cesiumlang/cesium#22.

Cesium 0.2.0, in development (dev at 53dc38a) · GitHub