SA0028: Overlapping memory areas

Function

Determines the points due to which two or more variables occupy the same storage space.

Reason

If two variables occupy the same storage space, the code may behave very unexpectedly. This must be avoided in all cases. If the use of a value in different interpretations is unavoidable, for example once as DINT and once as REAL, you should define a UNION. Also, via a pointer you can access a value typed otherwise without converting the value.

Importance

High

Sample:

In the following sample both variables use byte 21, i.e. the memory areas of the variables overlap.

PROGRAM MAIN
VAR
    nVar1 AT%QB21  : INT;        // => SA0028
    nVar2 AT%QD5   : DWORD;      // => SA0028
END_VAR