FORTRAN 77 Language Reference

AUTOMATIC

The AUTOMATIC @ statement makes each recursive invocation of the subprogram have its own copy of the specified items. It also makes the specified items become undefined outside the subprogram when the subprogram exits through a RETURN statement.

AUTOMATIC vlist

Parameter 

Description 

vlist

List of variables and arrays  

Description

For automatic variables, there is one copy for each invocation of the procedure. To avoid local variables becoming undefined between invocations, f77 classifies every variable as either static or automatic with all local variables being static by default. For other than the default, you can declare variables as static or automatic in a STATIC @, AUTOMATIC @, or IMPLICIT statement. See also the discussion of the -stackvar option in the Fortran User's Guide.

One usage of AUTOMATIC is to declare all automatic at the start of a function.

Example: Recursive function with implicit automatic:


       INTEGER FUNCTION NFCTRL( I )
       IMPLICIT AUTOMATIC (A-Z)
       ...
       RETURN
       END

Local variables and arrays are static by default, so in general, there is no need to use SAVE. You should use SAVE to ensure portability. Also, SAVE is safer if you leave a subprogram by some way other than a RETURN.

Restrictions

Automatic variables and arrays cannot appear in DATA or SAVE statements.

Arguments and function values cannot appear in DATA, RECORD, STATIC, or SAVE statements because f77 always makes them automatic.

Examples

Example: Some other uses of AUTOMATIC:


       AUTOMATIC A, B, C 
       REAL P, D, Q 
       AUTOMATIC P, D, Q 
       IMPLICIT AUTOMATIC (X-Z) 

Example: Structures are unpredictable if AUTOMATIC:


demo% cat autostru.f
       AUTOMATIC X
       STRUCTURE /ABC/
       INTEGER I
       END STRUCTURE
       RECORD /ABC/ X     X is automatic. It cannot be a structure.
       X.I = 1
       PRINT '(I2)', X.I
       END
demo% f77 -silent autostru.f
demo% a.out
*** TERMINATING a.out
*** Received signal 10 (SIGBUS)
Bus Error (core dumped)
demo%

Restrictions

An AUTOMATIC statement and a type statement cannot be combined to make an AUTOMATIC type statement. For example, AUTOMATIC REAL X does not declare the variable X to be both AUTOMATIC and REAL; it declares the variable REALX to be AUTOMATIC.