Subroutines are invoked by a call statement in the calling program unit. Functions simply appear in assignments (and other contexts) in the same way that variables appear. A main program that calls the subroutine and function defined on the previous page is given here:

Although subroutines and functions have similarities, they are not the same. Subroutines modify input variables, and they must be brought into action with a call statement. Functions have return values, and their names work like variables in the caller as well as in the function body. Thus, dot2 is declared as a real variable in the above program. Functions can also modify input variables just like subroutines, but it is generally recommended not to do so.

Note that the above example assumes sub1 and dot2 are external subprograms, i.e., they are defined in a separate file, or two separate files, or in a distinct program section after the main program's end statement. External subprograms can be called from any linked program unit.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement