Silverfrost Forums

Welcome to our forums

Access violation with 64 bit compiler

27 Feb 2025 10:38 #31950

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.

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
27 Feb 2025 11:50 #31954

Ken

Thank you for the bug report which I have logged for investigation.

1 Mar 2025 7:42 #31959

The following edit removes the problem

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 ?

4 Mar 2025 3:33 #31970

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.

Please login to reply.