Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

:= Used for an Output Parameter

In a call’s named argument list, := and => are direction-keyed: := writes a value into an INPUT (or IN_OUT) parameter, while => captures a value out of an OUTPUT parameter into a caller variable. Using := for an OUTPUT parameter is a typo for => and silently produces broken code.

Erroneous code example:

FUNCTION_BLOCK fb
VAR_INPUT  in_val  : DINT; END_VAR
VAR_OUTPUT out_val : DINT; END_VAR
    out_val := in_val + 1;
END_FUNCTION_BLOCK

PROGRAM main
VAR
    instance : fb;
    captured : DINT;
END_VAR
    instance(in_val := 5, out_val := captured);  // invalid: '=>' expected for an output parameter
END_PROGRAM

To fix, use => for the output parameter:

PROGRAM main
VAR
    instance : fb;
    captured : DINT;
END_VAR
    instance(in_val := 5, out_val => captured);  // correct
END_PROGRAM