- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I have a program that associates a pointer to an instance of a derived type, then checks whether the pointer is associated with the intended object. When I compile the program with ifort (19.0.4.243), the associated() function returns false.
The program is as follows:
module mod_pointer_association
type mytype
end type mytype
contains
subroutine test_association(obj)
class(mytype), target, intent(in)::obj
class(mytype), pointer::ptr
ptr=>obj
if (.not. associated(ptr)) then
print *, "ptr not associated"
error stop
end if
if (.not. associated(ptr, obj)) then
print *, "ptr not associated with obj"
error stop
end if
end subroutine test_association
end module mod_pointer_association
program test_pointer_association
use mod_pointer_association
type(mytype), target::myobj
call test_association(myobj)
end program test_pointer_association
The program produces the following output when compiled with ifort 19.0.4.243:
$ ./test_pointer_association
ptr not associated with obj
Which suggests that either the => or the associated intrinsic function did not perform the function I expect it to, because the associated function returned False when called with the pointed-to variable as the target, immediately after using => to associate the pointer.
The same program produces no output (as expected) when compiled with gfortran 9.2.0.
링크가 복사됨
3 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hi @jhaiducek
can you please try to add something to your derived type?
If I add an integer for example, your program works as you expect. Is there a real use case where you want to have an empty derived type or is this just a toy example?
Best
Tobias