Basic DataTypes
Like any regular programming language, Type-C provides basic built-in data types. These types have a guaranteed fixed size, ensuring that the data they represent occupies a constant amount of memory, regardless of the platform. This is crucial for low-level operations and provides more predictable behavior for high-performance computing tasks.
Name | Explanation | Range |
---|---|---|
u8 | 8bit wide unsigned integer | 0 to 255 |
i8 | 8-bit wide signed integer | -128 to 127 |
u16 | 16-bit wide unsigned integer | 0 to 65,535 |
i16 | 16-bit wide signed integer | -32,768 to 32,767 |
u32 | 32-bit wide unsigned integer | 0 to 4,294,967,295 |
i32 | 32-bit wide signed integer | -2,147,483,648 to 2,147,483,647 |
u64 | 64-bit wide unsigned integer | 0 to 18,446,744,073,709,551,615 |
i64 | 64-bit wide signed integer | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
f32 | 32-bit wide floating number | 3.4 × 10^38 (7 digits) |
f64 | 64-bit wide floating point number | 1.7 × 10^308 (15 digits) |
bool | Boolean value (8-bit sized) | true or false |
void | Usually a return type for functions that has no return value | |
null | Used both as a type and a value, to indicate that an object is nullable |
Type-C does not provide C compatibility types for basic types, instead, u8 is compatible with C99 uint8_t, same for all others.
Type Casting between basic types
Type casting in not an instant instruction, inorder to attempt to maintain type safety, Type-C will cast an intermediate type to the target type. This is to prevent loss of data or unexpected results, when applicable.
For example:
In the above example, x is a floating point number, and z is an unsigned integer. The compiler will first convert x into u32, then to u8.