Typed LiteralsΒΆ

With the exception of REAL/LREAL constants (LREAL is always used here), CODESYS uses the smallest possible data type when calculating with IEC constants. If you want to use another data type, then you can use typed literals without having to declare the constants explicitly. When doing this, provide the constants with a prefix that indicates the type.

Syntax:

<type>#<literal>

<type> defines the desired data type; possible values: BOOL, SINT, USINT, BYTE, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, LREAL. You must capitalize the entire type name.

<literal> defines the constants. The entry must match the data type defined in <Type>.

Example:

var1 := 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.