Array constants in a module

Get the following two different behaviours using modules, depending on how I compile them (using gf90 6.1-5):

two files:
t1.f90:

module constants
  implicit none
  logical, dimension(5), parameter   :: &
       lfalse5=(/.false.,.false.,.false.,.false.,.false./)
  logical, dimension(5), parameter   :: &
       ltrue5=(/.true.,.true.,.true.,.true.,.true./)
end module constants

t2.f90

program t2
  use constants
  implicit none
  print*,lfalse5
  print*,ltrue5
end program t2

Now watch what happens

$ pgf90 t1.f90 t2.f90
$ ./a.out
  F  F  F  F  F
  T  T  T  T  T

whereas

$ pgf90 -c t1.f90
$ pgf90 t2.f90
$ ./a.out
  F  F  F  F  F
  F  F  F  F  F

Any ideas?

Hi Che,

You need to add “t1.o” to your link line.

% pgf90 t1.f90 -c
% pgf90 t2.f90 t1.o
t2.f90:
% a.out
  F  F  F  F  F
  T  T  T  T  T
  • Mat

Ah. Oops. I thought that it was neccessary only that the module file exist. Thanks.

Hi Che,

A mod file contains the definition of a module but the object file contains the initialized data.

  • Mat

Right-o. Many thanks.