There must be something I'm misunderstanding.
I'm attempting to use an assumed rank unlimited polymorphic variable to store data. When I do this I either get access violations or corrupted data. I built a little toy problem to showcase the issue (listed below). The first is an access violation and the second is the corrupted data.
Access Violation
real, target :: x
class(*), pointer :: x_ptr
x = 5.6
x_ptr => x
call do_stuff(x_ptr)
contains
subroutine do_stuff(item)
class(*), dimension(..), intent(in) :: item
select rank(item)
rank(0)
select type(item) !<--- this is where the debugger crashes
type is (real)
print *, item
end select
end select
end subroutine do_stuff
Corrupted Data
real, target :: x
class(*), pointer :: x_ptr
x = 5.6
x_ptr => x
call do_stuff(x_ptr)
contains
subroutine do_stuff(item)
class(*), dimension(..), intent(in) :: item
select rank(item)
rank(0)
call do_stuff_inner(item)
end select
end subroutine do_stuff
subroutine do_stuff_inner(item)
class(*), intent(in) :: item
select type(item)
type is (real)
print *, item ! prints 4.735692598010119E-312
end select
end subroutine do_stuff_inner
I appreciate any explanation of what I'm doing wrong. I'm using intel fortran oneapi 2023.0.0.25839. Also to test for posting it does work on this compiler https://www.onlinegdb.com/online_fortran_compiler
ifx (IFX) 2024.2.0 20240602
using no compiler flags -ijb@ijb-SER:~/play/stack/fortran$ ifx unp1.f90; ./a.out 5.600000
. Could you edit the question to show the exact compilation line you are using in each case just to check that it isn't a compiler flag that is causing the issue.