Navigation bar
  Start Previous page
 88 of 156 
Next page End 83 84 85 86 87 88 89 90 91 92 93  

82
It is permissible to directly assign between any combination RAM-based, Persistent Memory and Program
Memory variables defined using the same structure.  Similarly, direct comparison between like structures
(equality and inequality only) is supported.
3.26 Data Type Implementation Information
This section provides more information on the technical details of the fundamental data types and
variants.  Although this information is generally not needed to write properly functioning programs it is
provided for those who are interested and for the special cases where knowledge of such implementation
details may help you implement your application.
To review, the table of fundamental data types introduced earlier in this manual is reproduced here with
an additional column indicating the amount of space required for each type.
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.26.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.22.  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.26.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.26.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 string’s 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
Previous page Top Next page