- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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?
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable