سؤال

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
هل كانت مفيدة؟

المحلول

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()

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top