I have the following FORTRAN
SUBROUTINE SETPATHS(INPUT)
!DEC$ ATTRIBUTES DLLEXPORT::SetPaths
CHARACTER*20 INPUT
CHARACTER*20 DIRECTORY
DIRECTORY = 'ABCDEFG'
WRITE(6, *) 'INPUT LEN_TRIM = ', LEN_TRIM(INPUT)
WRITE(6, *) 'DIRECTORYLEN_TRIM = ', LEN_TRIM(DIRECTORY)
END SUBROUTINE
And I’m calling the function from C#, passing in ‘ABCDEFG’.
When I set a breakpoint on my debugger, INPUT and DIRECTORY have the exact same characters. Both have ‘ABCDEFG’ followed by the same number of trailing spaces.
However, the program outputs
INPUT LEN_TRIM = 20
DIRECTORYLEN_TRIM = 7
Is this correct behavior? If the two strings have the same values, why does LEN_TRIM give different results?
Update: I found this documented problem (although it’s not my Intel 8.1 compiler). http://support.microsoft.com/kb/89131
By explicitly padding my C# StringBuilder with trailing spaces, the LEN_TRIM behaved as expected. This Microsoft KB seems to be related.
It is strange, however, that in the debugger the trailing spaces appeared even before I did the explicit padding.