英文:
Twincat : variable := null
问题
我在TwinCAT的SCL项目中工作,初始化LREAL变量时遇到问题。我尝试使用"null"值来表示未初始化状态,但变量总是被初始化为0。我还尝试使用"UNINITIALIZED"或"INITIAL_VALUE"标识符,但它们似乎不起作用。我需要帮助找到一种正确表示TwinCAT中未初始化LREAL变量的方法。我尝试使用"null"值来表示未初始化状态,但变量总是被初始化为0。我还尝试使用"UNINITIALIZED"或"INITIAL_VALUE"标识符,但它们似乎不起作用。我需要帮助找到一种正确表示TwinCAT中未初始化LREAL变量的方法。
英文:
I am working on a SCL project in TwinCAT and I am having trouble with initializing a LREAL variable. I have tried using the "null" value to represent an uninitialized state, but the variable always ends up being initialized to 0. I have also tried using the "UNINITIALIZED" or "INITIAL_VALUE" identifiers, but they don't seem to work. I need help finding a way to properly represent an uninitialized LREAL variable in TwinCAT.
I have tried using the "null" value to represent an uninitialized state, but the variable always ends up being initialized to 0. I have also tried using the "UNINITIALIZED" or "INITIAL_VALUE" identifiers, but they don't seem to work.I need help finding a way to properly represent an uninitialized LREAL variable in TwinCAT.
答案1
得分: 2
LREAL是一种基本类型,因此无法为其赋空值。位的每个组合表示实际数字 - 有一些例外,如NaN、+Infinity和-Infinity。
你可以创建一个指向LREAL的指针。数值为0的指针是空的 - 它不指向任何东西。然后,在实现部分,你可以使用__NEW为指针分配一个地址。
声明:
myPointer : POINTER TO LREAL;
myBool : BOOL;
实现:
// 指针仍然为0
IF myBool THEN
myBool := FALSE;
myPointer := __NEW(LREAL, 1);
// 现在指针被分配了一个地址,因此不为0
END_IF
英文:
LREAL is a primitive type and therefore cannot be nulled. Every combination of bits represents actual number - with few exceptions for NaN, +Infinity and -Infinity
What you can do is create a pointer to LREAL. Pointer of value 0 is null - it's not pointing to anything. Then, in implementation part, you can assign an address to your pointer using __NEW
Declaration:
myPointer : POINTER TO LREAL;
myBool : BOOL;
Implementation:
// pointer still 0
IF myBool THEN
myBool := FALSE;
myPointer := __NEW(LREAL, 1);
// pointer is now assigned an address, therefore not 0
END_IF
答案2
得分: 0
在TwinCAT中,我认为不存在空值。一旦定义了一个变量,它就会被设置为默认值。对于LREAL类型的变量,默认值是0.0。
英文:
There is no null in TwinCAT I think. Once you define a variable, it gets set to the default value. In case of an LREAL that is 0.0.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论