6 Programming
6-106
NJ-series CPU Unit Software User’s Manual (W501)
Observe the following precautions when you use the ST language in the user program.
Implicit Casts
If the data types of the operands do not match, as shown below, the data types are converted auto-
matically according to the implicit cast rules. If the implicit cast rules are not satisfied, a building error
occurs.
(1) When the data types of the operands in the expression on the right side of the
assignment statement are not the same
Example:
(2) When the data types of the operands on the right and left sides of the assignment
statement are not the same
Example:
(3) When the data types of the operands in statement are not the same
Example:
The casting rules are described for the following three cases.
Casting Rules When the Right-hand Side of an Assignment Statement Is an
Arithmetic Expression
• For the right-hand operand, you can use any combination of the data types that are supported for
the operator operand.
• Of the operands on the right side, the operand with the highest rank is considered the data type of
the entire side. (Refer to the Data Type Ranking Table given below for the data type ranks.)
• If both an unsigned integer and a signed integer with the same ranks exist on the right side, the
data type of the right side is considered to be unsigned.
Data Type Ranking Table:
The higher the rank, the larger the range (absolute values and precision) of numerical values that
the data type can express.
Precautions for the ST Language
Rank Data type
1 USINT, SINT, and BYTE
2 UINT, INT, and WORD
3 REAL
4 DINT, UDINT, and DWORD
5 LREAL
6 LINT, ULINT, and LWORD
A: = INT#10 + SINT#2;