Is mixing types allowed in ST (Structured Text)

4.3k views Asked by At

I wonder if it is allowed by the standard (IEC 1131-3) to mix different data types in an expression.

Example

VAR A : BOOL;
    B : INT;

(* ... *)

IF (B AND C) THEN
  ...
END_IF
2

There are 2 answers

0
Owen On BEST ANSWER

You must use the explicit type conversion functions when converting "down" in types. "up" conversion is done implicitly.

VAR A : BOOL;
    B : INT;
(* ... *)
IF (INT_TO_BOOL(B) AND C) THEN
  ...
END_IF

There are all forms of these type conversion in the form of TYPEA_TO_TYPEB()

0
avra On

It will not compile. Type conversion is needed since ST is type strict as Pascal.