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

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

pacobraxe
初學者
735 檢視
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 積分
2 回應
Steven_L_Intel1
735 檢視
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.
jimdempseyatthecove
榮譽貢獻者 III
735 檢視

I suppose the user could use INOUT.

回覆