Skip to main content

Attribute: nameprefix

The attribute defines a prefix for variables of a structured data type. The prefix must be prepended to the identifier of variables that are declared by this type. The static analysis checks this naming convention.

Insert location: In the line before the declaration of a structured data type

Syntax:

{attribute 'nameprefix' := '<prefix>'}

Example

In the following example, Static Analysis issues a message for pB because the variable name does not begin with "point".

{attribute 'nameprefix' := 'point'}
TYPE DATAPOINT :
STRUCT
    iX: INT;
    iY: INT;
END_STRUCT
END_TYPE

PROGRAM PLC_PRG
VAR
    pointA : DATAPOINT;
    pB : DATAPOINT;
END_VAR
pointA.iX := 1;
pointA.iY := 10;
pB.iX := 2;
pB.iY := 20;

Error message after static analysis: Invalid variable name 'pB': Expected prefix 'point'