Incorrect Results Concatenated Character Functions as Argument PSS ID Number: Q70252 Article last modified on 04-08-1993
4.01 4.10 5.00 | 4.10 5.00
MS-DOS | OS/2
The information in this article applies to: |
- Microsoft FORTRAN for MS-DOS, versions 4.01, 4.1, and 5.0 - Microsoft FORTRAN for OS/2, versions 4.1 and 5.0 |
Summary:
Programs compiled with Microsoft FORTRAN versions 4.01, 4.10, and 5.00 that concatenate two or more character functions in an argument of a CALL statement can give incorrect results when executed under DOS or OS/2.
The initial CALL to the subroutine works correctly, but any subsequent calls ignore the concatenation and truncate the character argument. For the problem to occur, this subroutine must take the concatenated character functions as an argument, and this argument must be declared as CHARACTER() within the subroutine.
To avoid this problem, assign the concatenated argument to a temporary variable and use the temporary variable in the CALL statement.
Microsoft has confirmed this to be a problem in Microsoft FORTRAN versions 4.01, 4.10, and 5.00. This problem was corrected in Microsoft FORTRAN version 5.10.
More Information:
The following program example illustrates the problem:
character c*4 call b(c()//c()) call b(c()//c()) end subroutine b(s) character*(*) s write (*,'(T2,A)') s return end character*4 function c() c = 'abcd' return end
The program produces the following output:
abcdabcd abcd
The following output should be produced:
abcdabcd abcdabcd
Assigning the concatenated argument to a temporary variable and using the temporary variable in the CALL statement will prevent the problem from occurring. The following program illustrates this solution:
character c*4 character temp*8 temp = c()//c() call b(c()//c()) call b(temp) end subroutine b(s) character*(*) s write (*,'(T2,A)') s return end character*4 function c() c = 'abcd' return end
=================================================================
Copyright Microsoft Corporation 1993.