Types

All constants, variables, functions and expressions have an associated type. BlitzMax supports the following types:

DescriptionSyntaxMinimum ValueMaximum Value
8 bit unsigned integerByte0255
16 bit unsigned integerShort065535
32 bit signed integerInt-2^31+2^31-1
64 bit signed integerLong-2^63+2^63-1
32 bit floating pointFloat(+/-)10^-38(+/-)10^38
64 bit floating pointDouble(+/-)10^-308(+/-)10^308
16 bit unicode stringString
ObjectTypename
ArrayElementType[]
FunctionReturnType(Parameters)
PointerValueType Ptr
VariableVariableType Var

Integers are used to store simple numeric data without any fractional part. Unsigned integers can only store positive values, while signed integers can store both positive and negative values.

Floating point values are used to store numeric data which may have a fractional part.

Strings are used to store sequences of characters: letters, punctuation, digits and so on. Use strings for storing non-numeric data such as names.

Arrays are used to store sequences of variables. A variable within an array is accessed by 'indexing' the array with an integer offset. Please refer to the arrays sections for more information on arrays.

Objects are instances of user-defined types. Please refer to the user-defined types section.

Type conversions

The following type conversions are performed automatically by BlitzMax when necessary - for example, when assigning an expression to a variable, or when passing an expression to a function:

Source typeTarget type
IntegerFloating point, String
Floating pointInteger, String
ObjectBase object
ObjectByte pointer
ArrayByte pointer, ElementType pointer
FunctionByte pointer
PointerByte pointer

You can also convert types explicitly using a cast operation. This takes the form of a type specifier followed by an expression in brackets.

Explicit casting allows you to perform the following extra conversions:

Source typeTarget type
StringInteger, Floating point
IntegerPointer
PointerInteger
PointerPointer
ObjectDerived object

Type balancing

When performing arithmetic operations such as addition or multiplication, it is possible to provide mismatched argument types. For example, the addition operator may be used to add an integer value to a floating point value. But what type should the result be?

BlitzMax decides the result type by balancing the argument types. Both arguments are then converted to the result type before the operator is applied.

The rules governing type balancing are:
If either argument is Double then result is Double
else if either argument is Float then result is Float
else if either argument is Long then result is Long
else result is Int