相关疑难解决方法(0)

Fortran是否具有未定义的行为?

在C和C ++中,有许多操作会导致未定义的行为,即允许编译器执行所需操作的情况。示例包括在取消分配变量后使用变量,两次取消分配变量以及取消引用空指针。

Fortran是否也具有未定义的行为?我看了一份规范草案,但未能在其中找到任何东西。例如,在释放变量之后使用变量肯定会导致程序崩溃,还是它会默默地做错事?

fortran

8
推荐指数
2
解决办法
144
查看次数

你能在 Fortran 中测试空指针吗?

我正在尝试使用 来学习 Fortran2018 gfortran。在使用指针时,我注意到似乎没有测试空指针的工具。所以我有两个问题:

  1. Fortran 中真的没有(直接)方法来测试指针是否为空指针或“准备使用”吗?
  2. 如果没有,为什么迄今为止 Fortran 中不认为有必要?

更实际地说,在下面的代码片段中:我们如何在执行过程中的任何时刻找出分配给p是否“安全”?allocate(可能会想象一个更复杂的、nullify和语句序列deallocate。)

program test
      implicit none
      real, pointer :: p

      ! p = 333.333 ! Segfault, p is neither defined, nor allocated
      ! Since p is not defined, checking whether it's 
      ! associated to a target gives arbitrary results:
      print *, "Start: Pointer p associated? ", associated(p) ! Result: True or False

      nullify(p) ! Now p is defined, but `null`
      print *, "Nullyfied: …
Run Code Online (Sandbox Code Playgroud)

fortran gfortran null-pointer

6
推荐指数
2
解决办法
992
查看次数

标签 统计

fortran ×2

gfortran ×1

null-pointer ×1