Raw pointers

A pointer stores a native memory address. Xenon keeps pointer operations explicit in both types and expressions.

Pointer types

Add * to a type to form a pointer. Pointer types may be nested, and void* represents an untyped memory address.

int* number;
byte** byteTable;
void* memory;

Address and dereference

The address-of operator & obtains a pointer to an addressable value. The dereference operator * reads or writes the pointed-to value.

int value = 10;
int* pointer = &value;

int copy = *pointer;
*pointer = 42;

Null and readonly data

null represents an empty pointer value. A readonly T* pointer provides read-only access to the pointed-to data.

byte* output = null;

byte First(readonly byte* input)
{
    return *input;
}

The restriction applies to access through this pointer. const is reserved for compile-time constant declarations and is not a pointer qualifier.

Members and indexing

Use -> for member access through a struct pointer. Indexing computes the address of an element and returns the value stored there.

Player* player = GetPlayer();
player->Health -= 10;

int first = values[0];
values[1] = 22;