Types

The built-in types and type forms you use to describe values in Chic.

Built-in types

Chic is statically typed. Write a type after :, or use := to let the compiler infer it from the initializer.

TypeMeaning
i8, i16, i32, i64Signed integers, with 8, 16, 32, or 64 bits.
u8, u16, u32, u64Unsigned integers of the same widths.
byteAn unsigned 8-bit type, like u8.
f32, float32-bit floating-point numbers.
f64, double64-bit floating-point numbers.
boolA boolean value: true or false.
charAn 8-bit character value.
runeA 32-bit Unicode code point; string iteration yields runes.
stringA native UTF-8 pointer-and-length value.
cstringAn alias for ^char, used with C strings.
voidNo return value; also used in untyped pointers such as ^void.
TypeInfo, any, SourceLocationCompiler-provided structures for type metadata, type-erased values, and source locations.
Type names such as i32 and string are built-in identifiers. The Keywords page lists reserved words separately.

Declaring values

count : i32 = 42       // explicit type
name := "Chic"         // inferred string
var index := 0         // mutable binding

Bindings are read-only by default. Add var when you need to assign a new value.

Use :: to declare a compile-time constant. Its value must be known at compile time. You can let Chic infer the type from the value, or specify the type before =.

FormMeaning
<identifier> :: <value>A compile-time constant with an inferred type.
<identifier> :: <type> = <value>A compile-time constant with an explicit type.
BufferSize :: 4096            // inferred type
PacketLimit :: u16 = 65_535  // explicit type

Composed types

FormMeaning
^TA pointer to a value of type T.
[N]TAn array with fixed-size storage for N elements.
[?]TAn array whose length is inferred from its initializer.
[]TA non-owning view over contiguous elements.
[T, U]A tuple containing multiple values.
func(T) -> UA callable function type.
funcptr(T) -> UA raw, context-free function pointer for native ABI boundaries.
values : [3]i32 = {10, 20, 30}
view : []i32 = values[:]
pointer : ^i32 = &values[0]
text : string = "hello"
c_text : cstring = c"hello"

User-defined types

Declare your own types with struct, enum, union, or raw_union. An alias gives an existing type another name.

alias UserId : i64

Point : struct {
    x : f32 = 0
    y : f32 = 0
}