Using forward declarations v16
When you want to invoke a subprogram, you must declare it in the hierarchy of blocks in the standalone program prior to where you invoke it. In other words, when scanning the SPL code from beginning to end, the subprogram declaration must appear before its invocation.
However, you can construct the SPL code so that the full declaration of the subprogram appears in the SPL code after the point in the code where it's invoked. (The full declaration includes its optional declaration section, its mandatory executable section, and optional exception section.)
You can do this by inserting a forward declaration in the SPL code prior to its invocation. The forward declaration is the specification of a subprocedure or subfunction name, formal parameters, and return type if it's a subfunction.
You must specify the full subprogram consisting of the optional declaration section, the executable section, and the optional exception section in the same declaration section as the forward declaration. However it can appear following other subprogram declarations that invoke this subprogram with the forward declaration.
Typical use of a forward declaration is when two subprograms invoke each other:
test_max invokes subfunction
add_one, which also invokes subfunction
test_max. A forward declaration is required for one of the subprograms, which is implemented for
add_one at the beginning of the anonymous block declaration section.
The resulting output from the anonymous block is as follows: