是否有 Fortran 编译器选项用于警告写入后写入冲突?
假设您有以下代码:
INTEGER :: num_samples
num_samples = 10000
num_samples = 1
显然,第一个 num_samples = 10000
没有执行任何操作,它的存在可能表明程序员错误(例如,程序员打算注释掉以下行,反之亦然) )。是否有任何 Fortran 编译器会警告此类写入后写入错误,如果有,哪些选项会打开警告? (我也很感兴趣是否有带有此类警告的 C++ 编译器,以及是否有提供此类警告的 Java IDE,但现在我专注于 Fortran 方面。)
Let's say you have the following code:
INTEGER :: num_samples
num_samples = 10000
num_samples = 1
Obviously, the first num_samples = 10000
does nothing, and its existence probably indicates a programmer error (e.g., the programmer meant to comment out the following line, or vice-versa). Are there any Fortran compilers that will warn for such write-after-write errors, and if so what options turn on the warning?
(I'm also interested if there are C++ compilers with such warnings, and if there are Java IDEs that provide such warnings, but right now I'm focusing on the Fortran side of things.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我的角度来看,这是一个奇怪的问题。您提到的这种先写后写的情况是一个逻辑错误。编译器主要检测语法错误。在某些情况下,逻辑错误可能会表现为语法错误,但并非总是如此。
逻辑错误意味着您在实现算法时犯了错误。您只有在测试时才能注意到它。或者您也可以尝试静态程序分析(如 steabert 提到的)。
看一下函数式编程语言。由于不变性,写后写的情况不会发生。 ;-)
This is kind of strange question from my point of view. This write-after-write situation you mentioned is a logical error. Compilers detect mostly syntax errors. In some cases logical error may reveal themselves as syntax errors but not always.
A logical error means that you made a mistake in implementing your algorithm. You can notice it only upon testing. Or you can also try static program analysis (as steabert mentioned).
Take a look at functional programming languages. Due to immutability write-after-write situation just can't happen. ;-)