Dear all,
today a colleague of mine came across a very peculiar problem. In a very simple fortran program the result of 3**1 = 1, which is obviously not correct. We do not understand this problem at all.
The following program
!*******************************************
program main
implicit none
integer n3,k3
c
data k3/3/
n3 = 1
write (0,) ’ test0: k3,n3,k3n3 : ',k3,n3,k3n3
c
n3 = 2
write (0,) ’ test1: k3,n3,k3n3 : ',k3,n3,k3n3
c
n3 = 3
write (0,) ’ test2: k3,n3,k3n3 : ',k3,n3,k3n3
!
end
!******************************************
compiled without any flags (pgf90 test.f) gives the following output:
test0: k3,n3,k3n3 : 3 1 1
test1: k3,n3,k3n3 : 3 2 1
test2: k3,n3,k3**n3 : 3 3 1
Compiling the same program with debugging information (-g), with the Intel compiler (ifort test.f), or using reals rather than integers for either n3 or k3 does give the correct output:
test0: k3,n3,k3n3 : 3 1 3
test1: k3,n3,k3n3 : 3 2 9
test2: k3,n3,k3**n3 : 3 3 27
Has anyone come across this problem before? Am I missing something very obvious or is it a compiler bug?
We are using release 5.2 of the Portland compiler and the problem occurred on workstations running OpenSuse 10.2.
Thanks in advance for any help.
Bert van Ulft