Author Message
mecej4

Joined: 31 Oct 2006
Posts: 1371 Posted: Mon Aug 10, 2020 1:12 am    Post subject: Access violation during compilation FTN95 aborts with an access violation (attempting to read from location 0000000C) when asked to compile the following simplified version of John Campbell's adaptation of Arjen Markus's quicksort in a recent thread, please see http://forums.silverfrost.com/viewtopic.php?t=4280 . The access violation occurs whether or not the /64 option is specified.

 Code: module qsort_m contains  subroutine test_sort (N)    integer N    integer, allocatable :: ia(:), ia_sort(:)    real, allocatable :: aa(:) !     allocate ( aa(N), ia(N), ia_sort(N) )     call random_number (aa)     ia = nint(aa*1023.0)     deallocate(aa)     print 10,n, ia !     ia_sort = qsort_int ( ia )     print 10,n,ia_sort  10 format(1x,i3,(4x,10I6)) !  end subroutine test_sort  recursive function qsort_int ( data ) result ( sorted )     integer, dimension(:), intent(in) :: data     integer, dimension(1:size(data))  :: sorted     if ( size(data) > 1 ) then         sorted = (/ qsort_int(pack(data(2:), data(2:) <  data(1))), &                                 pack(data(1:), data(1:) == data(1)),  &                     qsort_int(pack(data(2:), data(2:) >  data(1))) /)     else         sorted = data     endif   end function qsort_int  end module     Program test_sort_int   use qsort_m    integer n     N = 5     call test_sort(N)  end Program test_sort_int   mecej4

Joined: 31 Oct 2006
Posts: 1371 Posted: Mon Aug 10, 2020 2:44 am    Post subject: Here is a second version of the program, with the sorting algorithm slightly changed to preserve the order of items that match the pivot element.

 Code: module qsort_m     implicit none  contains   recursive function qsort_int ( data ) result ( sorted )     integer, dimension(:), intent(in) :: data     integer, dimension(1:size(data))  :: sorted     integer ilt, ieq, igt     if ( size(data) > 1 ) then         ilt = count(data < data(1))         if(ilt > 0)then            sorted(1:ilt) = pack( data, data < data(1) )            if(ilt > 1)sorted(1:ilt) = qsort_int(sorted(1:ilt))         endif         ieq = count(data == data(1))         if(ieq > 0)then            sorted(ilt+1:ilt+ieq) = pack( data, data == data(1) )         endif         igt = count(data > data(1))         if(igt > 0)then            sorted(ilt+ieq+1:) = pack(data,data > data(1))            if(igt > 1)sorted(ilt+ieq+1:) = qsort_int(sorted(ilt+ieq+1:))         endif     endif   end function qsort_int end module qsort_m Program test_sort_int    use qsort_m    integer n    integer, allocatable :: aa(:), aa_sort(:) !    N = 5    allocate ( aa(N), aa_sort(N) )    aa = (/ 204, 158, 835, 774, 932 /)    write (*,10) aa    aa_sort = qsort_int ( aa )    write (*,10) aa_sort 10 format(1x,5I10) !  end program test_sort_int

With other compilers, I get the expected output

 Code: 158       204       774       835       932

With FTN95 (32-bit) this program starts running but aborts with Stack Overflow. Compiled with /64, the program aborts with Access Violation. Compiled with /check, the 32-bit program runs to completion but the output is

 Code: 56687580  56687580  56687580  56687580  56687580

With /check /64, the program aborts, saying this about Line-6:

 Code: Attempt to call a routine with an incorrect or missing INTERFACE regarding argument number one, which needs to be declared as assumed-shape in both the caller and callee at address ...   Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1