Pragmas and attributes for Static Analysis Light
A pragma or an attribute can be used to exclude certain parts of the code from the check. Use the pragma {analysis ...}, to turn off coding rules in the implementation part and the attribute {attribute 'analysis' := '...'}, to turn off coding rules in the declaration part.
Requirement: You have activated the rules in the project properties.
In addition, you can use the attribute {attribute 'no-analysis'} to exclude programming objects from the static analysis.
![]() | Rules that are disabled in the project properties cannot be activated by a pragma or attribute. |
![]() | Rule SA0004 (Multiple writes access on output) cannot be disabled by a pragma. |
Pragma {analysis ...}
You can use the pragma {analysis -/+<rule number>} in the implementation part of a programming block in order to disregard individual coding rules for the following code lines. Coding rules are deactivated by specifying the rule numbers preceded by a minus sign ("-"). For activation they are preceded by a plus sign ("+"). You can specify any number of rules in the pragma with the help of comma separation.
Insertion location:
- Deactivation of rules: In the implementation part of the first code line from which the code analysis is disabled with {analysis - ...}.
- Activation of rules: After the last line of the deactivation with {analysis + ...}.
- For rule SA0164, the pragma can also be inserted in the declaration part before a comment.
Syntax:
- Deactivation of rules:
- one rule: {analysis -<rule number>}
- several rules: {analysis -<rule number>, -<further rule number>, -<further rule number>}
- Activation of rules:
- one rule: {analysis +<rule number>}
- several rules: {analysis +<rule number>, +<further rule number>, +<further rule number>}
Samples:
Rule 24 (only typed literals permitted) is to be disabled for one line (i.e. in these lines it is not necessary to write "nTest := DINT#99") and then enabled again:
{analysis -24}
nTest := 99;
{analysis +24}
nVar := INT#2;Specification of several rules:
{analysis -10, -24, -18}Attribute {attribute 'analysis' := '...'}
You can use the attribute {attribute 'analysis' := '-<rule number>'} to switch off certain rules for individual declarations or for a complete programming object. The code rule is deactivated by specifying the rule number(s) with a minus sign in front. You can specify any number of rules in the attribute.
Insertion location:
above the declaration of a programming object or in the line above a variable declaration
Syntax:
- one rule: {attribute 'analysis' := '-<rule number>'}
- several rules: {attribute 'analysis' := '-<rule number>, -<further rule number>, -<further rule number>'}
Samples:
Rule 33 (unused variables) is to be disabled for all variables of the structure.
{attribute 'analysis' := '-33'}
TYPE ST_Sample :
STRUCT
bMember : BOOL;
nMember : INT;
END_STRUCT
END_TYPE
Checking of rules 28 (overlapping memory areas) and 33 (unused variables) is to be disabled for variable nVar1.
PROGRAM MAIN
VAR
{attribute 'analysis' := '-28, -33'}
nVar1 AT%QB21 : INT;
nVar2 AT%QD5 : DWORD;
nVar3 AT%QB41 : INT;
nVar4 AT%QD10 : DWORD;
END_VAR
Rule 6 (concurrent access) is to be disabled for a global variable, so that no error message is generated if write access to the variable occurs from more than one task.
VAR_GLOBAL
{attribute 'analysis' := '-6'}
nVar : INT;
bVar : BOOL;
END_VARAttribute {attribute 'no-analysis'}
You can use the {attribute 'no-analysis'} attribute to exclude an entire programming object from the static analysis check. For this programming object no checks are carried out for the coding rules, naming conventions and forbidden symbols.
Insertion location:
above the declaration of a programming object
Syntax:
{attribute 'no-analysis'}
Samples:
{attribute 'qualified_only'}
{attribute 'no-analysis'}
VAR_GLOBAL
…
END_VAR{attribute 'no-analysis'}
PROGRAM MAIN
VAR
…
END_VAR