View previous topic :: View next topic |
Author |
Message |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Feb 27, 2025 11:38 am Post subject: Access violation with 64 bit compiler |
|
|
The following code runs correctly with the 32 bit compiler.
A run time access violation occurs when compiled and run with the 64 bit compiler.
Code: | module test_mod
implicit none
contains
function nextfreeunit() result( iunit )
! Returns the next available Fortran I/O unit in the range 10 to 99
integer :: i, ios, iunit
logical :: lopen
iunit = 0
do i = 10, 99
inquire ( unit = i, opened = lopen, iostat = ios )
if ( ios .eq. 0 ) then
if ( .not. lopen ) then
iunit = i
return
end if
end if
end do
end function nextfreeunit
function isfree(i) result (yes)
integer, intent(in) :: i
integer :: ios
logical :: lopen, yes
inquire ( unit = i, opened = lopen, iostat = ios )
if ( ios .eq. 0 .and. .not. lopen) then
yes = .true.
else
yes = .false.
end if
end function isfree
end module test_mod
program p
use test_mod
implicit none
print*, nextfreeunit()
print*, isfree(10)
end program p |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Thu Feb 27, 2025 12:50 pm Post subject: |
|
|
Ken
Thank you for the bug report which I have logged for investigation. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Sat Mar 01, 2025 8:42 am Post subject: |
|
|
The following edit removes the problem
Code: | program p
use test_mod
implicit none
logical :: is_unit
integer :: lu
lu = nextfreeunit()
is_unit = isfree(10)
print*, lu
print*, is_unit
! print*, nextfreeunit()
! print*, isfree(10)
end program p |
I have also had what may be similar problems recently when using a function in a print/write statement.
Evaluating the function first removes the problem, althouigh the use of a function in a write statement is allowed.
I am not sure if it is now allowed for the function to itself perform (internal) I/O ? |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Tue Mar 04, 2025 4:33 pm Post subject: |
|
|
In general recursive IO is not permitted in FTN95. It is permitted in certain cases such as this INQUIRE and the fact that it failed is an x64 bug.
This failure has now been fixed for the next release of FTN95. |
|
Back to top |
|
 |
|