Variable Types
A variable type defines what can be represented by that variable, as well as the ammount of storage the variable will take up.
Contents
Integer types
Signed integers can be positive or negative, but there is no fractional part. They are typically used in maths or graphical areas, but not so much when dealing with individual bits.
Unsigned integers can only be positive. Unsigned integers will double the range of a variable if it is known the value can never be negative. Unsigned integers are useful for bit-masking and other logical operations, but are not usually used in mathematical operations as these will usually require a signed value.
BOOL
Icon: | |
Range: | 0 or 1 |
Bit Depth: | 1-bit unsigned integer |
A Boolean value is either true or false. In Flowcode, this means 1 or 0, respectively. On download, this may take up 1 byte or a single bit, depending on the compiler.
Boolean values are used typically to set flags. Though internally a BOOL is stored as an integer, it is considered bad practice to mix Boolean values and integers in expressions.
BYTE
Icon: | |
Range: | 0 to 255 |
Bit Depth: | 8-bit unsigned integer |
A byte is the smallest storage unit most processors are able to read from in a single instruction. A byte can be used to store a single value or its bits may be used as flags, almost like a compact array of BOOLs.
INT
Icon: | |
Range: | -32768 to 32767 |
Bit Depth: | 16-bit signed integer |
UINT
Icon: | |
Range: | 0 to 65535 |
Bit Depth: | 16-bit unsigned integer |
LONG
Icon: | |
Range: | -21474836648 to 21474836647 |
Bit Depth: | 32-bit signed integer |
A 32-bit integer is useful for processing larger values and most integer-arithmetic uses found in embedded devices.
ULONG
Icon: | |
Range: | 0 to 4294967295 |
Bit Depth: | 32-bit unsigned integer |
An unsigned 32-bit value offers the largest integer value of any of the types, and because of this, many of the simulation-only functions in Flowcode use ULONG, because simulation memory is not a consideration.
Floating point
A floating point value can represent a much wider range of values than an integer can, but at a loss of accuracy over large ranges. Floating point values when downloaded will be 64-bit if the target supports them, or 32-bit if it does not.
FLOAT
Icon: | |
Range: | -Infinite to +Infinite |
Bit Depth: | 32-bit signed |
Float is a keyword in Flowcode and so cannot be used for variable, property or component names.
Mathematical operations such as a = b + c will be processed as an integer calculation if a, b or c are integer values.
for example you would expect 2.5 * 2 to equal 5 but in the world of integers the calculation only sees 2.5 * 2 = 4, the real portion of the number is lost.
The keyword float can be used to force a calculation to be done using floating point maths instead of integer maths.
e.g. FloatVar1 = FloatVar2 + float IntVar1
Did you know numeric constants such as 35 are also considered as integer values.
Using the float keyword or changing the constant value to for example 35.0 would force the value to be recognised as a floating point type variable.
Special types
Flowcode also supports some structured types to help with programs.
STRING
Icon: | |
Range: | 0 to 255 per character |
Bit Depth: | 8-bit unsigned array. Default size of the array is 20. |
A string is a byte-array used to store text. Hence in many circumstances a string and a byte array are interchangeable.
One important difference is in Flowcode strings terminate at a null (0x00) character. This means the first zero-value byte that is encountered in the string marks the end of the string. If a string contains the exact number of characters specified in the declaration it will not contain a terminating zero, in all other cases it will. Not leaving room in the string variable for the null character can be dangerous as it may potentially allow unwanted behaviour such as reading/writing RAM address space of other variables or stack.
String is a keyword in Flowcode and so cannot be used for variable, property or component names.
Numeric values and variables can easily be converted to a string by using the keyword sting before the variable.
e.g. StringVar1 = "Temperature: " + string IntVar1
HANDLE
Icon: | |
Range: | Undefined |
Bit Depth: | 32-bit unsigned value |
An object handle is used to reference a more complicated piece of data (such as a file, Flowcode component or block of text) whose internal format is not known. Flowcode provides many simulation macros that use handles to easily pass data around.
In an embedded context, a handle can be thought of as a pointer to memory, except Flowcode manages the handles so referencing a non-existent handle will not cause any fatal errors.
A handle value of zero is considered null and invalid to Flowcode.