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 int8 {
    BEGIN = 0,
    MIDDLE,
    END
}

function types

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

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

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

struct/union types

type Person struct {
    uint8 age;
    char* name;
    union {
        int32 employee_nr;
        uint32 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 int32[10];