Skip to main content

Rules

  • An identifier must not contain spaces or special characters.

  • The underscore is recognized.

    For example, A_BCD and AB_CD are treated as two different identifiers.

  • Multiple consecutive underscores are not permitted.

  • There is no case sensitivity.

    For example, VAR1 and var1 refer to the same variable.

  • The length of an identifier is unrestricted.

We recommend that you apply the Recommendations in addition to the items that you need to consider specifically for variables declaration. By doing this, you get the best possible harmonization when assigning names.

  • An identifier must not be declared two times locally.

  • An identifier can be used more than one time globally.

    If a local variable has the same name as a global variable, then the local variable has priority within the POU.

  • An identifier is not permitted to be identical to a keyword.

    Example: Scope of VAR_Global

  • A variable that is declared in a global variable list can have the same name as a variable defined in another GVL.

    CODESYS provides features that extend the standard for the namespace or scope of variables:

    • Global namespace operator

      An instance path that begins with a dot always opens a global namespace. If there is a local variable (for example, ivar) that has the same name as a global variable, then you refer to the global variable as .ivar.

    • The name of a global variable list can define the namespace uniquely for the include variables. Therefore, you can declare variables with the same name in different global variables list and still uniquely reference by prepending the list name.

      Example: globlist1.ivar := globlist2.ivar; (* ivar from GVL globlist2 is copied to ivar in GVL globlist1 *)

    • Variables that are defined in the global variable list of a library included in the project can be addressed uniquely according to the following syntax:

      <name scope library>.< GVL name>.<variable name>

      Example: globlist1.ivar := lib1.globlist1.ivar (* ivar from GVL globlist1 in library lib1 is copied to ivar in GVL globlist1 *)

  • When inserting a library, you also use the Library Manager to define a namespace. In this way, you can make unique references to a library POU or library variable by <namespace library >.<POU name\|variable name>. Note that when libraries are nested, you need to reference the namespaces of all libraries are in succession.

    Example: If Lib1 is referenced by Lib0, then the POU func in Lib1 is addressed by Lib0.Lib1.fun: ivar := Lib0.Lib1.fun(4, 5); (* return value from func is copied to variable ivar in the project *)

Backtick identifiers

By using backticks, characters can also be used in identifiers that are not normally permitted in identifiers, such as special characters. The acute accent character is used for backticks: ´ (Unicode: U+02CA)

The use of backticks is recommended in order to be able to use the same identifiers in CODESYS as in other programming languages or documents, such as circuit diagrams.

Any character may be used between two backticks, except line breaks and other backticks. Keywords are also allowed as identifiers between backticks.

Examples:

´Variable+9´

´INT´

The backticks are part of each identifier and therefore var1 and ´var1´ are two different identifiers.

Example 304. Example
PROGRAM PLC_PRG
VAR
    var1 : INT;
    ´var1´: INT;
END_VAR

var1 := var1 + 1;
´var1´ := 12;