gfortran bug?

Brooks Moses brooks.moses@codesourcery.com
Wed Dec 6 23:04:00 GMT 2006


Ray Nachlinger wrote:
> The following program produces strange results.

It's a very strange program.

>       integer len_l,n
>       parameter (n = 5, len_l = 2)
>       logical l(n),lt
>       parameter (lt = .true.)
> c
>       call repeat(.true.,len_l,n,   l(1))

First off, in Fortran-77 style programming (which this is) where you're 
not using modules or contained procedures or INTERFACE statements, each 
program unit is compiled separately.  This means that the main program 
has no idea what arguments the "repeat" subroutine is actually 
expecting, and trusts you to get it right.

What you're passing here is a single default-kind logical, the values 5 
and 2, and a default-kind logical array of length 5.  Compare this to 
the actual subroutine:

>       subroutine repeat(a,len,num,   b)
>       integer num,len,k,j
>       integer*2 a(num,*),b(num,*)

Here, the subroutine expects to get an integer*2 array of size 5 by 
something unknown, the two size numbers, and another integer*2 array of 
size 5 by something unknown.  Moreover, in the actual code:

>       do 2100 k = 1, num
>       do 2100 j = 1, len
>       b(j,k) = a(j,k)

Here, we find that your code assumes that the "something unknown" in 
those arrays is expected to be at least 2.

Thus, conceptually, this program is treating "a" as if it's an integer*2 
array with at least 10 elements.  However, it's looking for that in a 
place where you only gave it a single logical constant.  I have no idea 
what's actually in the memory it's looking at once it gets past the part 
occupied by the logical constant, but it can't possibly be anything you 
expect.

(And, if the part where it's reinterpreting the bits in a logical 
variable as if it's an integer is something you're doing intentionally, 
you really should use the TRANSFER intrinsic function instead.)

- Brooks



More information about the Fortran mailing list