- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So i have this piece of code:
module asd contains function return_alloc() result(res) class(*), dimension(:), allocatable :: res integer, dimension(3) :: x x = 5 allocate(res, source = x) print *, transfer(res,(/1,1,1/)) endfunction subroutine print_x() class(*), dimension(:), allocatable :: test allocate(test, source = return_alloc()) print *, transfer(return_alloc(),(/1,1,1/)), "aa" print *, transfer(test,(/1,1,1/)), "bb", size(test) endsubroutine endmodule program xyxcxvxvcxcyc use asd call print_x() endprogram
The output is:
5 5 5
5 5 5
aa
bb 3
while it shoud be:
5 5 5
5 5 5
5 5 5 aa
5 5 5 bb 3
So for some reason the function return is empty but retained it's dimensions.
my question now is obviously what am I doing wrong?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IIRC, there is an open incident with Intel Fortran with the use of TRANSFER intrinsic in IO (e.g., PRINT statements) but presently I'm unable to locate any threads. Intel Fortran team might be to find the details, if this is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to ask - what is it you are really trying to do here? You seem to be abusing TRANSFER in my opinion.
At first I thought that it was not allowed for the SOURCE argument to TRANSFER be polymorphic, much less unlimited poiymorphic, but interp F03/0047 covered this and it is allowed. I think this should have worked as you desired.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was unable to find other reports with TRANSFER in I/O but I’ll keep looking. For now, I did reproduce/report the findings here to Development.
(Internal tracking id: DPD200419455)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then I also have found another interesting behaviour with this piece of code.
If I change line 14 to
print *, return_alloc(), "aa"
it compiles and gives the same output.
But if I change line 15 in the same manner, I get an error message saying i have to provide a user-defined I/O routine for polymorphic items, which should also apply to the above case.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page