SA0007: Address operators on constants
Function | Determines locations at which the ADR operator is used for a constant. |
Reason | A pointer to a constant variable cancels the CONSTANT property of the variable. The variable can be changed via the pointer without the compiler reporting this. |
Exception | In rare cases, it may make sense for pointer to a constant to be passed to a function. If this option is used, measures must be implemented to ensure that the function does not change the value that was passed to it. In this case, use VAR_IN_OUT CONSTANT if possible. |
Importance | High |
![]() | If the option Replace constants is enabled in the compiler options of the PLC project properties, the address operator for scalar constants (Integer, BOOL, REAL) is not allowed and a compilation error is issued. (Constant strings, structures and arrays always have an address.) |
Sample:
PROGRAM MAIN
VAR CONSTANT
cValue : INT := INT#15;
END_VAR
VAR
pValue : POINTER TO INT;
END_VARpValue := ADR(cValue); // => SA0007