STATIC AND AUTOMATIC STORAGE


Static storage is part of the program's memory that is retained for the duration of the program's or procedure's runtime. Automatic storage is part of the program's memory that is automatically allocated and released each time the procedure in which it is declared is called and ended respectively. Within a subprocedure, local variables are, by default, declared in automatic storage.

The STATIC keyword can be used on the definition specification within a subprocedure to force a local variable to have the STATIC storage attribute. When a local variable is set to STATIC, its content remains unchanged each time the subprocedure is evoked. There is only one copy of the variable for the duration of the entire runtime of the program. This includes recursively called subprocedures.

For example, if subprocedure P1 calls subprocedure P2, and P2 calls P1 (which is perfectly valid in RPG IV), variables declared as automatic storage (which is the default property) have new instances created (i.e., a second copy of the variable is automatically generated). Variables declared as static storage are assigned a storage location only the first time the subprocedure is evoked. Subsequent invocations use the original storage locations. This process doesn't affect the data within that location. Hence, the data stored within a static storage variable is available to each invocation.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net