06.03.2014 Views

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Specification Statements 5<br />

Rules and Behavior<br />

AUTOMATIC and STATIC declarations only affect how data is allocated in storage, as follows:<br />

• A variable declared as AUTOMATIC and allocated in memory resides in the stack storage<br />

area.<br />

• A variable declared as STATIC and allocated in memory resides in the static storage area.<br />

If you want to retain definitions of variables upon reentry to subprograms, you must use the SAVE<br />

attribute.<br />

Automatic variables can reduce memory use because only the variables currently being used are<br />

allocated to memory.<br />

Automatic variables allow possible recursion. With recursion, a subprogram can call itself<br />

(directly or indirectly), and resulting values are available upon a subsequent call or return to the<br />

subprogram. For recursion to occur, RECURSIVE must be specified in one of the following ways:<br />

• As a keyword in a FUNCTION or SUBROUTINE statement<br />

• As a compiler option<br />

• As an option in an OPTIONS statement<br />

By default, the compiler allocates local variables of non-recursive subprograms, except for<br />

allocatable arrays, in the static storage area. The compiler may choose to allocate a variable in<br />

temporary (stack or register) storage if it notices that the variable is always defined before use.<br />

Appropriate use of the SAVE attribute can prevent compiler warnings if a variable is used before it<br />

is defined.<br />

To change the default for variables, specify them as AUTOMATIC or specify RECURSIVE (in<br />

one of the ways mentioned above).<br />

To override any compiler option that may affect variables, explicitly specify the variables as<br />

AUTOMATIC or STATIC.<br />

NOTE. Variables that are data-initialized, and variables in COMMON and<br />

SAVE statements are always static. This is regardless of whether a compiler<br />

option specifies recursion.<br />

A variable cannot be specified as AUTOMATIC or STATIC more than once in the same scoping<br />

unit.<br />

If the variable is a pointer, AUTOMATIC or STATIC apply only to the pointer itself, not to any<br />

associated target.<br />

5-19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!