![]() ZBasic Language Reference
94
ZBasic Microcontrollers
Fundamental Data Types
Data Type Name
Range of Values
Size in Bytes
Boolean
True, False
1
Byte
0 to 255
1
Integer
-32,768 to 32,767
2
UnsignedInteger
0 to 65,535
2
Long
-2,147,483,648 to 2,147,483,647
4
UnsignedLong
0 to 4,294,967,295
4
Single
approx. ±1.4e-45 to ±3.4e+38
and 0.0
4
String
0 to 255 characters
See 3.28.2
The Boolean type, while occupying an entire byte, will always contain one of two values under normal
circumstances. The value True is represented by the value 255 and the value False by 0. If your
application has a need for a lot of Boolean variables it may be more efficient to use the Bit data type
described in Section 3.21. The primary disadvantage to using the Bit type is that it cannot be passed by
reference.
The Single type is implemented using the data format specified in the IEEE 754 standard for single
precision floating point numbers.
3.28.1 User-defined Type Details
The user-defined types in ZBasic are enumerations and structures. Enumerations are implemented using
a two-byte value to represent the enumeration member value. Structures are laid out in memory exactly
corresponding to the order in which the members are defined in the structure definition. Bit and Nibble
type members are aligned on bit and nibble boundaries, respectively. All other member types are aligned
on a byte boundary. Due to these alignment rules and depending on the specific structure definition,
there may be unused bits and/or nibbles within the structure. The number of bytes consumed by a
structure variable is the sum of the sizes of the members including the unused bits.
3.28.2 String Data Type Details
For the string data types, the storage requirements and implementation details vary depending on
compiler command line options, Option Directives and the type of string. For the String data type, if
Option AllocStr is enabled (as it is by default for ZBasic modules) each string variable requires four
bytes of storage in User RAM space plus additional space allocated from the dynamic memory allocation
heap to hold the characters of the string. This string storage strategy is called dynamic string allocation
because the space to hold the strings characters is dynamically allocated and will grow and shrink as
need be to accommodate the string value assigned to it. One additional advantage to using dynamically
allocated strings is that the string storage will never be overrun because it is changed dynamically and
limited to the maximum size of 255 characters automatically.
The 4 bytes of User RAM for a dynamically allocated string variable are used in the following manner:
|