FORTRAN 的 LEN_TRIM 对传递的参数的行为是否有所不同?
我有以下 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
我正在从 C# 调用该函数,并传入“ABCDEFG”。
当我在调试器上设置断点时,INPUT 和 DIRECTORY 具有完全相同的字符。两者都有“ABCDEFG”,后跟相同数量的尾随空格。
但是,程序输出
INPUT LEN_TRIM = 20
DIRECTORYLEN_TRIM = 7
这是正确的行为吗?如果两个字符串具有相同的值,为什么 LEN_TRIM 给出不同的结果?
更新:我发现了这个已记录的问题(尽管它不是我的 Intel 8.1 编译器)。 http://support.microsoft.com/kb/89131
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你使用什么编译器?这里是gfortran。
也尝试过 ifort,
我不知道 C# 接口如何引入问题,但 LEN_TRIM 的语义非常简单...如果你说字符串在调试中显示为相等,那么就会出现一些非常可疑的情况。
What compiler are you using ? here gfortran.
Tried with ifort as well
I don't know how the C# interface can introduce problems, but the semantics of LEN_TRIM are quite easy... if you say that the strings appear as equal in the debug, there's something very fishy going on.
它可能正在寻找终结符字符 char(0)。它可能与 \n 字符不同,
其他可能性是字符串长度未正确传递。 Fortran 77 字符串作为两个值传递:字符串指针和字符串长度。没有标准如何传递字符串长度,大多数编译器最后将其作为隐藏参数。为了兼容性,90 可能会做同样的事情。
it may be looking for Terminator character, char(0). it could be different from \n character
other possibility the string length was not passed correctly. fortran 77 string is passed as two values, string pointer and string length. there is no standard how string length is passed, most compilers stick it as a hidden parameter in the end. could be 90 does the same thing for compatibility.
通过使用尾随空格显式填充 C# StringBuilder,LEN_TRIM 的行为符合预期。 此 Microsoft 知识库似乎是相关的。
然而,奇怪的是,在调试器中,甚至在我进行显式填充之前就出现了尾随空格。
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.