SA0019: Implicit pointer conversions

Function

Determines implicitly generated pointer data type conversions.

Reason

In TwinCAT, pointers are not strictly typed and can be assigned to each other arbitrarily. This is a commonly used option and therefore not reported by the compiler. However, this may result in unwanted and unexpected access. For example, assigning the type POINTER TO DWORD to a pointer with the type POINTER TO BYTE can result in unwanted memory overwriting.

Therefore, always check this rule and suppress the message only in cases where you deliberately want to access a value with a different type.

Implicit data type conversions are reported with a different message.

Exceptions

1) BOOL ↔ BIT

2) Conversions from and to the POINTER TO BYTE data type are not checked by rule SA0019. They are always allowed.

Importance

High

PLCopen rule

CP25

Samples:

PROGRAM MAIN 
VAR
    nInt   : INT;
    nByte  : BYTE;
 
    pInt   : POINTER TO INT;
    pByte  : POINTER TO BYTE;
END_VAR
pInt  := ADR(nInt);
pByte := ADR(nByte);
 
pInt  := ADR(nByte);             // => SA0019
pByte := ADR(nInt);              // => SA0019
 
pInt  := pByte;                  // => SA0019
pByte := pInt;                   // => SA0019