- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you please explain the crash in the following program?
[fortran]
module A_m
implicit none
private
type, public :: A_t
private
character(len=1) :: dummy_char
contains
procedure :: DoSmth
end type
contains
subroutine DoSmth(this)
class(A_t), intent(in) :: this
write(*, "(A)") "A_t::DoSmth"
end subroutine DoSmth
end module A_m
module B_m
use A_m
implicit none
private
type, public :: B_t
private
class(A_t), pointer :: a => null()
contains
procedure :: GetA
procedure :: SetA
end type
contains
subroutine SetA(this, a)
class(B_t), intent(inout) :: this
class(A_t), pointer, intent(in) :: a
this%a => a
end subroutine SetA
function GetA(this) result(a)
class(B_t), target, intent(in) :: this
class(A_t), pointer :: a
a => this%a
end function GetA
end module B_m
program main
use A_m
use B_m
implicit none
class(A_t), pointer :: a
class(B_t), pointer :: b
class(A_t), pointer :: a_ptr
allocate(a, b)
call b%SetA(a)
! works with explicit pointer
a_ptr => b%GetA()
call DoA(a_ptr)
! crashes here
call DoA(b%GetA())
deallocate(a, b)
contains
subroutine DoA(a)
class(A_t), pointer, intent(in) :: a
if (.not.associated(a)) then
write(*, "(A)") "error"
else
call a%DoSmth()
end if
end subroutine DoA
end program main
[/fortran]
I believe that the program crashes because an implicit pointer is created at the statement "call DoA(b%GetA())".
Compiler version: XE 13.1
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am looking at this now.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page