Rules for identifier designation
Rules for identifiers of variables
-
An identifier must not contain spaces or special characters.
-
Capitalization is ignored. For example,
VAR1
andvar1
refer to the same variable. -
The underscore is recognized. For example,
A_BCD
andAB_CD
are treated as two different identifiers. Multiple consecutive underscores are not permitted. -
The length of an identifier is unrestricted.
Rules for multiple use of identifiers (namespaces)
-
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 must not be identical to a keyword, such as the scope
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.
For 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>
For 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 block or library variable by
<namespace library>.<block name|variable name>
. Note that when libraries are nested, you have to reference the namespaces of all libraries are in successionExample: If
Lib1
is referenced byLib0
, then the POUfunc
inLib1
is addressed byLib0.Lib1.fun
:ivar := Lib0.Lib1.fun(4, 5); (* return value from func is copied to variable ivar in the project *)
We recommend that you apply the following rules in addition to the items that you have to consider specifically for variables declaration. By doing this, you get the best possible harmonization when assigning names.
Recommendations for variable names
Whenever possible, you should name variables in Hungarian notation in applications and libraries. Find a meaningful, short, English name for each variable as a base name, which can consist of several words. Write the first letter of each word in uppercase, the remaining letters in lowercase. In front of the base name, append a prefix in lowercase to indicate the data type of the variable.
Example: iFileSize : INT;
Data Type |
Prefix |
Description |
---|---|---|
|
|
We expressly recommend |
|
Reserved |
|
|
|
Bit string; not for arithmetic operations |
|
|
Bit string; not for arithmetic operations |
|
|
Bit string; not for arithmetic operations |
|
|
Bit string; not for arithmetic operations |
|
|
Arithmetic integer data type, 8-bit |
|
|
Arithmetic integer data type, 8-bit |
|
|
Arithmetic integer data type, 16-bit |
|
|
Arithmetic integer data type, 16-bit |
|
|
Arithmetic integer data type, 32-bit |
|
|
Arithmetic integer data type, 32-bit |
|
|
Arithmetic integer data type, 64-bit |
|
|
Arithmetic integer data type, 64-bit |
|
|
Arithmetic floating-point data type, 32-bit |
|
|
Arithmetic floating-point data type, 64-bit |
|
|
Single-byte character string of variable length (default setting: 80 characters) |
|
|
Double-byte character string of variable length (default setting: 80 characters) |
|
|
Time duration, 32-bit |
|
|
Time duration, 64-bit |
|
|
Time of day, 32-bit |
|
|
Time of day, 64-bit |
|
|
Date and time |
|
|
|
|
|
Calender date |
|
|
Calender date |
|
|
|
|
|
|
Enumeration |
|
Example
VAR bySubIndix: BYTE; xFlag: BOOL; udiCounter: UDINT; END_VAR
Identifier |
Description |
Example |
---|---|---|
Nested declaration |
Prefixes are attached successively in the order of declaration. |
|
Function block instance Variable of user-defined data type |
Prefix: Abbreviation for the name of the function block or data type |
|
Local constant Local constant variable |
Prefix: |
|
Global variable |
An additional prefix is appended to the library prefix.
|
|
Global constants Global constant variable |
An additional prefix is appended to the library prefix.
|
|
Recommendations for variable names CODESYS V3.x libraries
Identifier |
Description |
Example |
---|---|---|
Variable |
Corresponds to the description for variable names, with the exception that global variables and constants do not require library prefixes because the namespace replaces the function. |
|
Recommendations for identifiers for user-defined data types (DUT)
Identifier for |
Description |
Example |
---|---|---|
Structures |
Library prefix followed by an underscore and a short, informative description of the structure. The associated prefix for created variables of this structure should follow the colon as a comment. |
|
Enumerations |
Library prefix followed by an underscore and the identifier in uppercase. Note: In past CODESYS versions, enumeration values > 16#7FFF caused errors because they were not automatically
converted to |
Declaration:
|
Recommendations for identifiers for user-defined data types (DUT) in CODESYS V3 libraries
Identifier for |
Description |
Example |
---|---|---|
DUT names in CODESYS V3 libraries |
The namespace replaces the need for the library prefix. Therefore, it is omitted. Enumeration values are also defined without a library prefix. |
Library with namespace
ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ
Declaration:
Usage in the application
|
Recommendations for identifiers for POUs, functions, function blocks, programs
Identifier for |
Description |
Example |
---|---|---|
POUs: Functions, function blocks, programs |
Library prefix followed by an underscore and a short, informative POU name. Like for variables, the first letter of each word is uppercase and all other letters are lowercase. We recommend that you compose the POU name from a verb and a noun. For function blocks, the associated prefix for created instances should follow the name as a comment. |
|
Actions |
Only actions that the block itself calls, beginning with |
Recommendations for identifiers for POUs in CODESYS V3 libraries
Identifier for |
Description |
Example |
---|---|---|
POU |
The library prefix is omitted because the namespace replaces the function of the library prefix. |
|
Method |
Only methods that the block itself calls, beginning with Otherwise, methods do not have a prefix. |
|
Interface Interface |
|
|
Recommendations for identifiers for visualizations




NOTICE

Note that a visualization is not named the same as another block in the project because this may cause problems when changing visualizations.