Skip to main content

Constant: Typed Literal

With the ecxeption of REAL or LREAL-Constants (in this case, always LREAL is used) the smallest possible data type is used when calculating with IEC constants. If you want to use a different data type, you can use typed literals to do this without having to declare the constant explicitly. Provide the constant with a prefix that defines the type.

Syntax

<type> # <literal>

<type> specifies the desired data type. Possible inputs are BOOL, SINT, USINT, BYTE, INT, UINT, WORD, DINT, UDINT, DWORD, REAL and LREAL. You must capitalize the type.

<literal> specifies the constant. The input must go to the below <type> specified data types match.

Example 193. Example

diVar := DINT#34;



If CODESYS cannot convert the constant into the target type without data loss, then an error message is issued.

You can use typed constants wherever you can use normal constants.