修改参数时出现Fortran总线错误

发布于 2024-10-07 15:56:30 字数 366 浏览 0 评论 0原文

每当我为参数分配新值时,都会收到总线错误。我不明白我是如何指向不存在的记忆的。我应该有权访问该地址,因为它是在参数列表中声明的,除非 Fortran 不允许在没有某些特殊声明的情况下修改参数。我的其余代码可以正常工作,没有错误。我把它简单地分为这个任务。

我正在 OS X 的终端上运行 gfortran (不确定是哪个版本,临时的)。

SUBROUTINE p_list (c_number, c_matrix)
    INTEGER     c_number
    INTEGER     c_matrix(8000,20)
!   ... 
    c_number = 1000
!   ...
END SUBROUTINE p_list

Whenever I assign a new value to a parameter, I get a bus error. I don't see how I'm pointing to non-existant memory. I should have access to this address, as it is declared in the parameter list, unless Fortran does not allow parameters to be modified without some special declaration. The rest of my code works without error. I've isolated it to simply this assignment.

I'm running gfortran (not sure which version, off-hand) from the terminal in OS X.

SUBROUTINE p_list (c_number, c_matrix)
    INTEGER     c_number
    INTEGER     c_matrix(8000,20)
!   ... 
    c_number = 1000
!   ...
END SUBROUTINE p_list

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

零度° 2024-10-14 15:56:30

你怎么称呼这个?我不了解现代的 FORTRAN,但我知道使用早期版本的 FORTRAN,您可能会通过传入常量(例如,通过调用 p_list(0, my_matrix))来使程序崩溃。这是因为 FORTRAN 通过引用隐式传递所有内容,包括常量(!)

How are you calling this? I don't know modern FORTRANs, but I know that with earlier versions of FORTRAN, you could crash a program like that by passing in a constant (e.g., by calling p_list(0, my_matrix)). That's because FORTRAN implicitly passed everything by reference, including constants (!)

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