是否有 Fortran 编译器选项用于警告写入后写入冲突?

发布于 2024-10-25 10:04:55 字数 309 浏览 2 评论 0原文

假设您有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不甘平庸 2024-11-01 10:04:55

从我的角度来看,这是一个奇怪的问题。您提到的这种先写后写的情况是一个逻辑错误。编译器主要检测语法错误。在某些情况下,逻辑错误可能会表现为语法错误,但并非总是如此。

逻辑错误意味着您在实现算法时犯了错误。您只有在测试时才能注意到它。或者您也可以尝试静态程序分析(如 steabert 提到的)。

我也很感兴趣是否有带有此类警告的 C++ 编译器,以及是否有提供此类警告的 Java IDE,但现在我专注于 Fortran 方面。

看一下函数式编程语言。由于不变性,写后写的情况不会发生。 ;-)

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).

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.

Take a look at functional programming languages. Due to immutability write-after-write situation just can't happen. ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文