- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Compiler: ifx (IFX) 2025.0.4
OS: Rocky Linux 8.9 (Green Obsidian)
I believe the pointer `px` should have size 0 the third time `method` is called, but it has size 5. Its array size is not being reset between calls, even though it becomes disassociated.
module myMod
implicit none
type, abstract :: base
end type
type, extends(base) :: extension
end type
contains
subroutine method(bool)
logical, intent(in) :: bool
class(base), allocatable, target :: x(:)
type(extension), pointer :: px(:) => null()
if (bool) allocate(extension :: x(5))
select type(dummy => x)
type is(extension)
px => dummy
print *, 'type'
class default
px => null()
print *, 'default'
end select
print *, size(px), associated(px)
end subroutine
end module
program main
use myMod
implicit none
call method(.false.)
call method(.true.)
call method(.false.)
end program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Calling size on a disassociated pointer is not permitted - the results are unpredictable.
"ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated. "
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Calling size on a disassociated pointer is not permitted - the results are unpredictable.
"ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated. "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I missed that when checking the standard. Thank you!

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