The syntax to define new types is very standard and uniform: type <name> <definition> Like all global declarations, they may also have the public specifier in front. Note that the public specifier is required when the type is used as a parameter, return type or a member of a public symbol.

The definition can be:

  • enum
  • struct or union
  • func
  • another type (for alias types)

enum types

enum types use the following syntax:

type State enum i8 {
    BEGIN = 0,

Note that all enum constants are in only available through the enum type namespace (eg State.BEGIN, not BEGIN).

function types

Instead of the obscure C syntax to defined function-pointer types, C2 uses the following:

public type Callback func void(i32 a, bool b);

This defines a function pointer type to functions that return nothing and require two arguments.

struct/union types

type Person struct {
    u8 age;
    char* name;
    union {
        i32 employee_nr;
        u32 other_nr;
    union subname {
        bool b;
        Callback cb;

alias types

Alias types are used to give a name to other types, like:

type CharPtr char*;
type Numbers i32[10];