使用 TO_<type> 转换而不是 <type>_TO_<type> 有什么缺点吗?

问题描述 投票:0回答:1

TwinCAT 和(我认为是)所有其他 IEC61131-3 语言都支持两种转换类型

<type>_TO_<type>
TO_<type>
。我想知道,使用后者有什么缺点吗?所以
TO_<type>
?例如,我有一个计算,我们都知道,输入额外的 5 个字母会影响你的一天;)

nResult : INT;
fDivisor : REAL;

// Does this perform any slower, or are there any cons to using it like this?
nResult := TO_INT(32767.0/fDivisor);
nResult := REAL_TO_INT(32767.0/fDivisor);
plc twincat structured-text iec61131-3
1个回答
0
投票

过去 1-2 年我只使用了速记函数

TO_REAL()
等,没有任何问题。它们大大简化了代码,您不需要编写那么多代码。

我 99% 确信 PLC 运行时不存在缺点/性能问题,因为编译器很可能只是在编译期间自动检查数据类型。

但是我还没有测量性能,但我能想到的唯一缺点是编译器在编译过程中需要检查一些数据类型。这应该是微不足道的。

© www.soinside.com 2019 - 2024. All rights reserved.