Fortran Coder

标题: Debug时 allocate 分配数组显示为 undefined [打印本页]

作者: hang719    时间: 2014-10-30 23:13
标题: Debug时 allocate 分配数组显示为 undefined
         1. module中声明了一个integer 型变量;         2. 这个变量的数值 在module中的一个子程序内从文件读入

         3. 在module内的另一个子程序中声明了一个具有allocatable特征的real 型数组;
         4. 用这个integer 型变量给这个real 型数组 allocate 内存。

        问题: 1. 编译没错,可是调试过程中,这个real型数,显示为 undefined array。
                       我用一个具体的数字代替这个integer型变,这个数组显示为 undefined address。
                       什么原因?
               
                   2.  我是这样解决的:我把这个allocatable特征的real 数组 放到module内声明,就没有问题了,但是违反了我的初衷。
                       有没有更好的办法?

作者: fcode    时间: 2014-10-31 08:49
从你的描述来说,没有问题。

我也不知道你的问题在哪儿,给代码吧,直观。
作者: aliouying    时间: 2014-10-31 11:15
不知道你怎么弄的,反正我这没问题
[Fortran] 纯文本查看 复制代码
   MODULE module_defi_Val
    Integer   :: iVal
    Contains
    Subroutine setValue()
    Implicit None
        iVal = 2
    Return
    End Subroutine setValue
    End MODULE module_defi_Val
!*****************************************************************************!
    MODULE module_defi_array
    Use module_defi_Val
    IMPLICIT NONE
    REAL(kind=8),allocatable :: x(:)
    CONTAINS
    Subroutine allocateArray()
    Implicit None
        Allocate( x(iVal) )
        x = 1
    Return
    End Subroutine allocateArray
    End MODULE module_defi_array
!*****************************************************************************!
    Program www_fcode_cn
    Use module_defi_Val
    Use module_defi_array
    Implicit None
    call setValue
    call allocateArray
    write(*,*) x
    Stop
    End Program www_fcode_cn

作者: hang719    时间: 2014-10-31 14:56
本帖最后由 hang719 于 2014-10-31 15:31 编辑
fcode 发表于 2014-10-31 08:49
从你的描述来说,没有问题。

我也不知道你的问题在哪儿,给代码吧,直观。 ...

代码太多,我写了个简化版,看5楼
作者: hang719    时间: 2014-10-31 15:27
本帖最后由 hang719 于 2014-10-31 15:30 编辑

我写了个简化版的。
[Fortran] 纯文本查看 复制代码
module  Test
    implicit none
    integer::n
contains

subroutine Set_n
    implicit none
    n=3
end subroutine

subroutine  Allocate_memory
    implicit none
    real(kind=8),allocatable::array(:)
   
    allocate(array(n))
   
    array(:)=1.0
   
    write(*,*)   array(1),array(2),array(3)
   
end subroutine

end module

program main
    use Test
    implicit none
    call Set_n
    call Allocate_memory
   
end program


断点设置在这里,这个是调试显示结果,数组显示undefined pointed/array。


但是输出结果是对的。





作者: hang719    时间: 2014-10-31 15:32
本帖最后由 hang719 于 2014-10-31 15:35 编辑
aliouying 发表于 2014-10-31 11:15
不知道你怎么弄的,反正我这没问题
[mw_shl_code=fortran,true]   MODULE module_defi_Val
    Integer   : ...

我的allocatable变量是想设置成某个子程序内的局部变量,你这个是全局变量,不太一样。看5楼。
作者: hang719    时间: 2014-10-31 15:33
aliouying 发表于 2014-10-31 11:15
不知道你怎么弄的,反正我这没问题
[mw_shl_code=fortran,true]   MODULE module_defi_Val
    Integer   : ...

我的allocatable变量是想设置成某个子程序内的局部变量,你这个是全局变量,不太一样。
作者: vvt    时间: 2014-10-31 15:53
通常来说,断点不要在表示结构的语句上,而应该在执行语句上。

你的调试器有 bug 吧?我这里一切 OK

QQ截图20141031155322.png (8.2 KB, 下载次数: 355)

QQ截图20141031155322.png

作者: hang719    时间: 2014-10-31 21:59
vvt 发表于 2014-10-31 15:53
通常来说,断点不要在表示结构的语句上,而应该在执行语句上。

你的调试器有 bug 吧?我这里一切 OK

还真是,估计是我的debug问题,




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2