Naming conventions

In the Naming Conventions tab you can define naming conventions. Their compliance is accounted for in the Static Analysis execution. You define mandatory prefixes for the different data types of variables as well as for different scopes, function block types, and data type declarations. The names of all objects for which a convention can be specified are displayed in the project properties as a tree structure. The objects are arranged below organizational nodes.

In the Naming Conventions tab, you will also find options that extend the configuration of the prefixes. You can use these options to configure how the expected overall prefix for variables/declarations should be composed.

Configuration of the naming conventions

Names

Nodes and elements for which a prefix can be defined

The number in brackets after each element, for example "PROGRAM (102)", is the prefix convention number that is output if the naming convention is not followed.

Prefix

You can define the naming conventions by entering the required prefix in this column.

Please note the following notes and options:

  • Several possible prefixes per line
    • Multiple prefixes can be entered separated by commas.
    • Example: "x, b" as prefixes for variables of data type BOOL. "x" and "b" may be used as prefix for Boolean variables.
  • Regular expressions
    • You can also use regular expressions (RegEx) for the prefix. In this case you have to use @ as additional prefix.
    • Example: "@b[a-dA-D]" as prefix for variables of data type BOOL. The name of the boolean variable must start with "b", and may be followed by a character in the range "a-dA-D".
  • Data type placeholder
    • For variables of the Alias data type and for properties you can use the data type placeholder "{datatype}" as prefix.
    • Example: Prefix for the variable data type Alias (33) = "{datatype}"

Prefixes for variables

Organizational node for all variables for which a prefix dependent on their data type or scope can be defined

Prefixes for POUs

Organizational node for all POU types and method validity ranges for which a prefix can be defined

Prefixes for DUTs

Organizational node for the DUT data types Structure, Enumeration, Alias or Union for which a prefix can be defined

Prefixes for user-defined types (NC0160)

Available from TC3.1 Build 4026

An organizational node for configuring a prefix for specific user-defined types, particularly those from libraries or for read-only types (e.g. PVOID, HRESULT).

For more information see: NC0160: User-defined type

 

Naming conventions 1:

Formation of the expected prefix

The prefix expected for the different declarations is formed depending on the configuration of the options found in the Options dialog.

On the Options page you will also find explanations on how the expected prefix is formed, as well as some samples.

Naming conventions 2:

Placeholder {datatype} with alias variables and properties

Please also note the possibilities of the placeholder {datatype}, which you can use for the prefix definition of alias variables and properties.

Naming conventions 3:

Local prefix definition for structured types

For variables of structured types, you can specify a prefix locally in the data type declaration using the 'nameprefix' attribute.

Sample output

The variable iCounter : INT; is declared. For INT variables, however, the prefix n is specified with the help of NC0014. The following error is therefore output in the Error list when the static analysis is performed:

"NC0014: Invalid variable name 'iCounter'. Expected prefix 'n'"

Temporary deactivation of naming conventions

Individual conventions can be disabled temporarily, i.e. for particular code lines. To this end you can add a pragma or an attribute in the declaration or implementation part of the code. For variables of structured types you may specify a prefix locally via an attribute in the data type declaration. For more information see: Pragmas and attributes.

 

Overview of naming conventions

For an overview of naming conventions, see Overview and description - (naming conventions).