Skip to main content

SA0170: Address of an output variable should not be used

Detects the code locations where the address of an output variable (VAR_OUTPUT, VAR_IN_OUT) of a function block is used.

Justification: It is not allowed to use the address of a function block output in the following way:

  • By means of the ADR operator

  • By means of REF=

Exception: No error is reported if the output variable is used within the same function block.

Importance: Medium

Example 128. Example

Function block FB1 has the VAR_OUTPUT variable iOutVal : INT;

The following access in another POU generates Error SA0170:

//FB1_inst is of type FB1
addr1 := ADR(FB1_inst.iOutVal);    //SA0170
refINT REF= FB1_inst.iOutVal;    //SA0179

The following access directly within the FB1 function block also generates the error:

//other is a POINTER TO FB1
ptr := ADR(other^.iOutVal);    //SA0170

The following access directly within the FB1 function block does not generate errors:

//iInputVal is a VAR_INPUT of FB1
iOutVal := iInputVal; 
//ptr is a POINTER TO INT
ptr := ADR(THIS^.iOutVal); 
ptr := ADR(iOutVal);

Output in the Messages view:

  • sa_icon_message.png SA0170: Should not take on the address of an output variable