Skip to content

Types

Cera’s type system is built around a single type keyword that defines a type — its fields, methods, and behavior. Where instances are stored — on the stack, the GC heap, or via raw pointers — is determined by how the type is used at the declaration site, not by the type definition itself.

Primitive Types

TypeSizeDescription
int64-bitSigned integer (default)
int8, int16, int32, int648—64 bitSized signed integers
uint8, uint16, uint32, uint648—64 bitUnsigned integers
float64-bitFloating point (default)
float32, float6432—64 bitSized floats
string—Immutable text
char8-bitSingle byte character
bool—true / false
hash64-bitHash value (via (hash)value cast)

User-Defined Types

The type keyword defines the field layout, methods, and behavior of a type:

type Point(int x, int y) { }
type Circle
{
float radius;
float Area() Math.PI * this.radius * this.radius;
}

See Type Definitions for constructors, destructors, inheritance, virtual methods, and full details.

Type Categories

The same type definition can be used in three ways at the declaration site:

DeclarationCategoryStorageLifetime
Point p;ValueStackScope-based
Point? p; / Point! p;GC referenceHeapGarbage collected
Point* p; / Point& p;Raw pointerHeap (manual)Manual delete*
Point a; // value on the stack
Point! b = new Point(1, 2); // non-null GC reference on the heap
unsafe {
Point* c = new* Point(3, 4); // raw pointer, manual lifetime
delete* c;
}

Vtable pointers are added depending on the category and whether the type uses virtual dispatch:

  • Values and raw pointers — a vtable pointer (8 bytes at offset 0) is only present when the type has virtual or abstract methods, or inherits from a type that does. Types without virtual methods have no vtable overhead.
  • GC references — always include a vtable pointer, even without virtual methods. The GC and reflection system use it for type identification.

See Type Definitions — Using Types for full memory layout details.

Arrays

SyntaxDescription
T[]Fixed-size array (value type)
T[*]Growable dynamic array

See Arrays for full details.

Callable Types

Function signatures as types, used for callbacks and higher-order functions:

int(int, int) operation = Math.Add;

See Callable Types for details.

Special Types

TypeDescription
objectUniversal GC reference — auto-boxes value types
dynDynamic dispatch — resolves fields and methods at runtime
voidNo value

See Object and Dyn for details.

Type Checks and Casts

if (value is int) { /* ... */ }
int n = value as int;
switch type (value)
{
case int i:
Console.WriteLine($"{i}");
break;
case string s:
Console.WriteLine(s);
break;
}

See Pattern Matching for more patterns.