Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 415

allocatable class(*) function return

$
0
0

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?


Viewing all articles
Browse latest Browse all 415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>