Global Declarations
Subroutine and format declarations are global declarations. No matter where you place them, what they declare is global (it’s local to a package, but packages are global to the program, so everything in a package is visible from anywhere). A global declaration can be put anywhere a statement can, but it has no effect on the execution of the primary sequence of statements—the declarations take effect at compile time.
This means you can’t conditionally declare subroutines or
formats by hiding them from the compiler inside a runtime conditional
like an if, since only the
interpreter pays attention to those conditions. Subroutine and format
declarations (and use and no declarations) are seen by the compiler no
matter where they occur.
Global declarations are typically put at the beginning or the end of your program, or off in some other file. However, if you’re declaring any lexically scoped variables (see the next section), you’ll want to make sure your format or subroutine definition falls within the scope of the variable declarations—if you expect it to be able to access those private variables.
Note that we sneakily switched from talking about declarations
to definitions. Sometimes it helps to split the
definition of the subroutine from its
declaration. The only syntactic difference
between the two is that the definition supplies a BLOCK containing the code to be executed, while the declaration doesn’t. (A subroutine definition acts as its own declaration if no ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access