Vala Reference Manual

Types

Vala supports four kinds of data types: value types, reference types, type parameters, and pointer types. Value types include simple types (e.g. char, int, and float), enum types, array types, and struct types. Reference types include object types, delegate types, and error types. Type parameters are parameters used in generic types.

Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object, and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other.

type: value-type reference-type nullable-type type-parameter pointer-type

Value types

Instances of value types are stored directly in variables. They are duplicated whenever assigned to another variable (e.g. passed to a method). For local variables, value types are stored on the stack.

value-type: struct-type enum-type array-type struct-type: type-name integral-type floating-point-type bool integral-type: char uchar short ushort int uint long ulong size_t ssize_t int8 uint8 int16 uint16 int32 uint32 int64 uint64 unichar floating-point-type: float double enum-type: type-name array-type: non-array-type [] non-array-type [ dim-seperators ] non-array-type: value-type object-type class-type delegate-type error-type dim-separators: , dim-separators ,

Struct types

Documentation

Simple types

Documentation

Integral types

Documentation

Floating point types

Documentation

The bool type

Documentation

Enumeration types

An enumeration type is a type containing named constants.

See enums.

Reference types

Instances of reference types are always stored on the heap. Variables contain references to them. Assigning to another variable duplicates reference, not object.

reference-type: object-type class-type delegate-type error-type weak-reference-type weak-reference-type: weak object-type weak class-type weak array-type weak delegate-type weak error-type object-type: type-name string class-type: type-name . Class delegate-type: type-name error-type: type-name

Weak reference types

Documentation

Array types

An array is a data structure that contains zero or more elements of the same type.

Delegate types

A delegate is a data structure that refers to a method, and for instance methods, it also refers to the corresponding object instance.

Error types

Instances of error types represent recoverable runtime errors.

Nullable types

An instance of a nullable type T? can either be a value of type T or null.

nullable-type: value-type ? reference-type ?

Pointer types

Unlike references, pointers are not tracked by the memory manager. The value of a pointer having type T* represents the address of a variable of type T. The pointer indirection operator * can be used to access this variable. Like a nullable object reference, a pointer can be null. The void* type represents a pointer to an unknown type. As the referent type is unknown, the indirection operator cannot be applied to a pointer of type void*, nor can any arithmetic be performed on such a pointer. However, a pointer of type void* can be cast to any other pointer type (and vice versa) and compared to values of other pointer types.

pointer-type: type-name * pointer-type * void*