Difference between revisions of "Blitz:Data types"

From Amiga Coding
Jump to: navigation, search
(Primitive Data Types)
m (Daedalus moved page Data types to Blitz:Data types)
(No difference)

Revision as of 00:53, 1 August 2015

Primitive Data Types

Blitz Basic / AmiBlitz supports six standard data types that can be stored in variables by your program. Five of these are used to store numbers in various formats, and a string data type is used to store strings of characters. The various properties and limitations of each type are listed below:

Name Extension Size Minimum Maximum Notes
Byte .b 1 byte (8 bits) -128 +127 Integer values only
Word .w 2 bytes (16 bits) -65536 +65535 Integer values only
Long / Long Word .l 4 bytes (32 bits) -231 +231 Integer values only
Quick .q 4 bytes (32 bits) -32768 +32767 Quick-float with fixed decimal point, +/-15 bit.16 bit format (1 in 65536 precision after decimal point). Quicker than emulating the float types in software but slower than integers and slower than float types using a hardware FPU.
Float .f 4 bytes (32 bits) -9*1018 +9*1018-1 Single-precision floating point number as supported by the Amiga's standard floating point libraries, +/-23bits+/-7 bits format. Slow to emulate in software but very fast if hardware FPU is used. Slower than integers.
Double Float .d 8 bytes (64 bits) -Huge +Huge Double-precision floating point number, +/-52bits+/-10 bits format. No software emulation so requires a hardware FPU to be used. Not supported in Blitz Basic 2.1 and earlier. Slower than single-precision float types.
String .s or $ Variable, dynamically increased as required Null (\0) String buffer size String of 8-bit characters in memory terminated automatically by a null character (\0). Size does not normally need to be declared. $ extension is included as in other BASIC dialects, and if used, must be included every time the variable is referenced.


Default Data Types

By default, any variables used in Blitz that are not explicitly defined as a particular type are created as quick types. The default type for variables not explicitly defined can be set using the DefType command: DefType .b In this example, all further variables created without a declared type will be of the byte type.

NewTypes

NewTypes are custom data types defined by your code. They contain one or more variables of any type grouped together. They are the equivalent of a Struct or Structure in C.