Print

Print


Hi all,

The NAG compiler is giving me a headache and I'm not sure if it's my fault or his. If I compile the code below (using "nagfor -nan test.f90") and execute, I get an "Runtime Error: *** Arithmetic exception: Floating invalid operation - aborting" at the assignement statement in sub. The "-nan" option is telling the compiler to initialize all variables with NaN's in order to catch usage of unitialized values. It seems that NAG is initializing the intent(out) argument (i.e. b) with NAN's upon entry to the routine but without working on a copy of the data. Since the same argument is passed twice, the valid content is being overwritten. I tried searching the Fortran standard if the code below is legal or not, and I think it is. Who's to blame?

Cheers,
Oliver

subroutine sub(a,b)
 implicit none
 real, intent(in) :: a
 real, intent(out) :: b
 b = a
end subroutine sub

program test
 implicit none
 real :: a
 a=1.0
 call sub(a,a)
 write(*,*) a
end program test