JohnyBergmann
Joined: 21 Nov 2005 Posts: 5
|
Posted: Wed Dec 07, 2005 6:49 am Post subject: problem with intent(in) dummy argument in read input list |
|
|
The following test program exposes a problem with the compiler, which does not detect the use of the dummy arguments a and b as input items.
Furthermore, on return from the function call, the actual arguments are modified in the calling program.
[pre]
module m
contains
integer function countlines(a,b)
integer, intent(in):: a,b
integer n, ios
ios = 0
n = 0
do while (ios == 0)
read(10,"(i4)",iostat=ios) a,b
if (a > b) then
n = n + 1
endif
enddo
countlines = n
end function countlines
end module m
program intent_1
use m
integer a,b,nlines
open(10,file="test.txt")
write(10,"(i4)") 5, 6
write(10,"(i4)") 7, 8
write(10,"(i4)") 3, 0
write(10,"(i4)") 9 ,7
rewind(10)
a = 1
b = 2
nlines = countlines(a,b)
print *,a,b,nlines
end program intent_1
[/pre]
Compiled with ftn95 intent_0.f90 /ISO /RES /LGO
the output is: 9 7 3
This would be the correct result with intent(inout) arguments, but in the present case one would expect a compile error.
Johny |
|