![forums.silverfrost.com Forum Index](templates/subSilver/images/logo_phpBB.gif) |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Moji
Joined: 30 Sep 2020 Posts: 27
|
Posted: Thu Jun 15, 2023 12:25 pm Post subject: chsort@ in 64-bit programs |
|
|
I noticed that chsort@ behaves differently in 32-bit and 64-bit programs, when the last argument is negative. It is ignored in 32-bit, but causes run time error in a 64-bit program.
Code: | PROGRAM CHSORT_TEST
IMPLICIT NONE
INTEGER :: arr(100),N
CHARACTER*5 :: SORT(100)
WRITE (*,*) 'Start'
N = -1
call chsort@ (sort,arr,N)
WRITE (*,*) 'END'
END
|
Last edited by Moji on Thu Jun 15, 2023 2:05 pm; edited 1 time in total |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1891
|
Posted: Thu Jun 15, 2023 1:13 pm Post subject: |
|
|
Your code does not issue a correct call to the FTN95 routine CHSORT@.
1. The second argument should be a character array with N elements. Your code has a scalar character variable.
2. The third argument should be the number of array elements that are to be sorted. It makes no sense to use -1 for this count, as your code does.
When a function is called with incorrect arguments, the behaviour of the program is "undefined", so what the incorrect code does in 32-bit versus 64-bit EXEs is of little to no interest. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Kenneth_Smith
Joined: 18 May 2012 Posts: 697 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu Jun 15, 2023 2:16 pm Post subject: |
|
|
This may help:
Code: | program test_chsort
implicit none
character(len=8):: sname(1:9) = ['Smith ','Jones ','Taylor ',&
'Brown ','Williams','Wilson ',&
'Watson ','Walker ','Walton ']
integer :: a(1:9)
integer :: n=9
integer :: i
call chsort@(a,sname,n)
do i = 1, n
print*, i, ' ', sname(a(i))
end do
end program test_chsort |
Returns
Code: | 1 Brown
2 Jones
3 Smith
4 Taylor
5 Walker
6 Walton
7 Watson
8 Williams
9 Wilson |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Moji
Joined: 30 Sep 2020 Posts: 27
|
Posted: Thu Jun 15, 2023 2:21 pm Post subject: Re: |
|
|
mecej4 wrote: | Your code does not issue a correct call to the FTN95 routine CHSORT@.
1. The second argument should be a character array with N elements. Your code has a scalar character variable.
2. The third argument should be the number of array elements that are to be sorted. It makes no sense to use -1 for this count, as your code does.
When a function is called with incorrect arguments, the behaviour of the program is "undefined", so what the incorrect code does in 32-bit versus 64-bit EXEs is of little to no interest. |
Thanks for the comment. The first argument has been modified. You are also right about the second point. This value is however set from other codes. I just made it simple for this sample code.
I just meant, that it would be a positive point, if even for "undefined" situations, both 32-bit and 64-bit behave similarly as it is the case for many other situations, like:
Code: | N = -1
DO I = 1, N
WRITE (*,*) I
END DO |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1891
|
Posted: Thu Jun 15, 2023 7:27 pm Post subject: |
|
|
Please note that the four lines of code that you showed as an example of "an undefined situation" has nothing undefined about its expected behaviour. When N = -1, the subsequent DO loop is not executed at all, so the four lines of code are equivalent to just one line:
Execution of this single statement is not expected to show any difference for 32-bit or 64-bit compilation. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|