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内声明,就没有问题了,但是违反了我的初衷。
有没有更好的办法?
从你的描述来说,没有问题。
我也不知道你的问题在哪儿,给代码吧,直观。 不知道你怎么弄的,反正我这没问题
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 15:31 编辑
fcode 发表于 2014-10-31 08:49
从你的描述来说,没有问题。
我也不知道你的问题在哪儿,给代码吧,直观。 ...
代码太多,我写了个简化版,看5楼 本帖最后由 hang719 于 2014-10-31 15:30 编辑
我写了个简化版的。
moduleTest
implicit none
integer::n
contains
subroutine Set_n
implicit none
n=3
end subroutine
subroutineAllocate_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:35 编辑
aliouying 发表于 2014-10-31 11:15
不知道你怎么弄的,反正我这没问题
MODULE module_defi_Val
Integer : ...
我的allocatable变量是想设置成某个子程序内的局部变量,你这个是全局变量,不太一样。看5楼。 aliouying 发表于 2014-10-31 11:15
不知道你怎么弄的,反正我这没问题
MODULE module_defi_Val
Integer : ...
我的allocatable变量是想设置成某个子程序内的局部变量,你这个是全局变量,不太一样。 通常来说,断点不要在表示结构的语句上,而应该在执行语句上。
你的调试器有 bug 吧?我这里一切 OK
vvt 发表于 2014-10-31 15:53
通常来说,断点不要在表示结构的语句上,而应该在执行语句上。
你的调试器有 bug 吧?我这里一切 OK
还真是,估计是我的debug问题,:-handshake
页:
[1]