我在gfortran中有两个延迟长度的字符数组。我分配其中一个,然后将另一个指向它。指针变量的字符长度正确,但数组大小错误。尝试访问指针中的信息时,程序终止并显示错误。
我正在用以下方法进行测试: GNU Fortran(MacPorts gcc8 8.2.0_2)8.2.0
下面的代码与Windows上的Intel Fortran一起正常工作。
program test
character(len=:), pointer, dimension(:) :: charvara
character(len=:), pointer, dimension(:) :: charvara_ptr
allocate(character(len=10) :: charvara(3))
charvara(:) = '0123456789'
print *, len(charvara)
print *, size(charvara)
print *, charvara
charvara_ptr => charvara
print *, associated(charvara_ptr, charvara)
print *, len(charvara_ptr)
print *, size(charvara_ptr)
print *, charvara_ptr
print *, 'end'
end program test
我希望charvara_ptr的长度,大小和内容与charvara相同,但我得到以下信息:
10
3
012345678901234567890123456789
T
1708412736
3
test(66553,0x7fff9e47c380) malloc: *** mach_vm_map(size=140734901800960) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc
Error termination. Backtrace:
#0 0x104fbe65f
#1 0x104fbeecd
#2 0x104fbf057
#3 0x104fbe0c9
#4 0x1050cc8e4
#5 0x1050c30db
#6 0x1050c8af5
#7 0x1050cbc6c
#8 0x1050cc712
#9 0x104fb3d80
#10 0x104fb3dde