Implicit Data Type Conversion
According to the IEC 61131-3 standard, some functions and function blocks provide implicit type conversion of the data types connected to their input and output formal parameters. Implicit data type conversion means that the data type is automatically converted into the required data type, i.e., no explicit data type conversion function is required in the code.
Functions/function blocks that support implicit data type conversion can process, for example, different data types at their formal parameters and automatically convert them. This make the blocks more flexible.
The IEC 61131-3 standard defines exactly which data types may be converted implicitly and for which conversions an explicit type conversion function must be used.
The following rules apply for implicit data type conversion:
- Implicit type conversion is only possible if the range and precision of the input data type are not affected, i.e., can be mapped to the range and precision of the output data type.
- ANY_NUM data types can be converted implicitly into other ANY_NUM data types.
ANY_DURATION data types can only be converted implicitly into other ANY_DURATION data types.
ANY_BIT data types can only be converted implicitly into other ANY_BIT data types.
ANY_DATE and STRING data types as well as user defined data types cannot be converted implicitly. - Implicit conversion is only possible, if the source data type is smaller than the target data type:
8 bit data types can be converted into 16, 32 and 64 bit types
16 bit data types can be converted into 32 and 64 bit types
32 bit data types can be converted into 64 bit types - For ANY_REAL data types the respective precision must be used:
REAL mantissa = 23 bit
LREAL mantissa = 52 bit - Unsigned integer data types are considered regarding their size, the sign bit is treated as "normal" most significant bit. Therefore, they can be implicitly converted into any larger ANY_NUM data types.
In the following table the possible implicit data type conversions are colored green. All other conversions are either impossible or can be performed by using an explicit type conversion function (if available).