Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

intent(out) for a derived type with an allocatable member

pacobraxe
Beginner
731 Views
Hi everybody!
I am confused because I wrote a little program which has a derived type:

type struc
integer :: n
integer, dimension(:), allocatable :: v
end type

I defined a variable in the program and gave it some values:

type(struc) :: s
s%n = 5

When I pass "s" to a subroutine where its corresponding dummy argument has intent(out), then "s%n" is set to 0 inside the subroutine! Is it normal? This does not happen if I erase the allocatable member "v" from "struc" type.

I am using version 9.1 of Intel compiler. I read that Fortran 95 standard is unclear about the intent attribute of derived types with pointer members, but I do not think it is connected to the previous problem...

Thanks a lot,
Paco
0 Kudos
2 Replies
Steven_L_Intel1
Employee
731 Views
When a dummy argument has INTENT(OUT), it becomes undefined on entry to the routine. If there are allocatable components, they are deallocated at that time. The values of other components are undefined, so even asking what the value of N is constitutes undefined behavior.
0 Kudos
jimdempseyatthecove
Honored Contributor III
731 Views

I suppose the user could use INOUT.

0 Kudos
Reply