dba
dba

Reputation: 493

gfortran: Force static memory allocation

I'm currently updating some old F77 fixed format code and compiling with gfortan.

Is there a way to obtain a warning when I do not use static memory allocation, e.g. if I call a subroutine and pass some dimension value that is not fixed at runtime?

Or would I have to use old f77 compilers?

EDIT:

Here is some code example:

      program test

        integer A,b
        read(*,*) b

        select case(b)
          case(50)
            A=40
          case(40)
            A = 50
        end select

        call arr(A)
      end

      subroutine arr(A)
        integer A
        double precision E(A,A)

        E(1,1) =10.
        E(42,41)= 41
        write(*,*)  E(42,41), A
      end

Upvotes: 1

Views: 1104

Answers (1)

You are using select case, which is Fortran 90. Therefore, using a Fortran 77 compiler is not an option. I am worried that you just have to be careful. If you stay away from allocatable, pointer and allocate, you just have to be sure that there are no automatic arrays. You can also disable stack allocation for small static arrays and other variables by -fno-automatic or similar.

Regarding your example, it indeed uses an automatic array. If you REALLY need to stay away from them, you have to declare the bounds as compile-time constants:

  subroutine arr(A)
    integer MAXA
    parameter (MAXA=1000)
    integer A
    double precision E(MAXA,MAXA)

    E(1,1) =10.
    E(42,41)= 41
    write(*,*)  E(42,41), A
  end

Upvotes: 2

Related Questions