primitive types

C2 has the following built-in primitive types:

  • bool. can be either true or false
  • i8, i16, i32, i64. The signed types
  • u8, u16, u32, u64. The unsigned types
  • f32, f64. Floating point types

There is also a builtin void type, used for pointers (eg void*) For convenience, the char keyword is also available and is identical to the i8 type.

Note that C2 does not have any type specifiers like signed, unsigned, long, short, etc.

c2 pseudo-module

The c2compiler always has a pseudo module called c2. This module is used to store some language symbols such as min/max values and things like build time, etc. For each integer type there exists a min/max value:

  • min_i8, max_i8
  • min_i16, max_i16
  • min_i32, max_i32
  • min_i64, max_i64
  • min_u8, max_u8
  • min_u16, max_u16
  • min_u32, max_u32
  • min_u64, max_u64
module foo;
import c2;

i32 highest = c2.max_i32;

It also includes some C type for mapping C declarations in libraries to C2 interface types. See External Libraries for more information.

pointer types

Pointer types are created by adding an asterix (*) after the type they refer to, like

void* a;
i8* b;
Point* c;

array types

Arrays in C2 differ from C arrays in that the [] always come right after the element type, so

void*[]  a;
Point[4] b;

For array types, C2 introduces a new operator, namely elemsof(). This returns the number of elements in an array and avoids C macros like:

#define ARRAY_SIZE(x) ( sizeof(x) / sizeof(x[0]) )

The sizeof() operator is also still available.