5.1.25 AUTOMATIC and STATIC attributes

With -fdec-static GNU Fortran supports the DEC extended attributes STATIC and AUTOMATIC to provide explicit specification of entity storage. These follow the syntax of the Fortran standard SAVE attribute.

STATIC is exactly equivalent to SAVE, and specifies that an entity should be allocated in static memory. As an example, STATIC local variables will retain their values across multiple calls to a function.

Entities marked AUTOMATIC will be stack automatic whenever possible. AUTOMATIC is the default for local variables smaller than -fmax-stack-var-size, unless -fno-automatic is given. This attribute overrides -fno-automatic, -fmax-stack-var-size, and blanket SAVE statements.

Examples:

subroutine f
  integer, automatic :: i  ! automatic variable
  integer x, y             ! static variables
  save
  ...
endsubroutine
subroutine f
  integer a, b, c, x, y, z
  static :: x
  save y
  automatic z, c
  ! a, b, c, and z are automatic
  ! x and y are static
endsubroutine
! Compiled with -fno-automatic
subroutine f
  integer a, b, c, d
  automatic :: a
  ! a is automatic; b, c, and d are static
endsubroutine