Recursive method call Permalink

Within the implementation, a method can call itself, either directly by means of the ‎THIS‎ pointer, or by means of a local variable for the assigned function block.

  • <return value variable> := <POU name> . <method name> ( <argument passing> );

    Direct call of the relevant function block instance with the ‎THIS‎ pointer

  • <return value variable> := <POU name> . <method name> ( <argument passing> );

    Call by means of a local variable of the method that temporarily instantiates the relevant function block

A compiler warning is issued in the case of a recursive ⮫ call. If the method is provided with the pragma ‎{attribute 'estimated-stack-usage' := '<estimated stack size in bytes>'}‎, then the compiler warning is suppressed.

For an implementation example, see the "Attribute: ⮫ 'estimated-stack-usage'" chapter.

To call methods recursively, it is not enough to specify only the method name. If only the method name is specified, then a compiler error is issued: “Program name, function or function block instance expected instead of”