Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Can MOVE_ALLOC be used with associate-names in an ASSOCIATE construct?

$
0
0

Is the run-time behavior shown below with the following code correct?

program p

   implicit none

   type :: t
      character(len=:), allocatable :: s
   end type t

   type(t), allocatable :: foo
   type(t), allocatable :: bar
   type(t), allocatable :: tmp

   foo = t( "foo" )
   bar = t( "bar" )

   asc: associate ( s1 => foo, s2 => bar )

      print *, "before swap: "
      print *, "  foo = ", s1%s
      print *, "  bar = ", s2%s

      !.. swap foo and bar
      call move_alloc(bar, tmp)
      call move_alloc(foo, bar)
      call move_alloc(tmp, foo)

      print *, "after swap: "
      print *, "  foo = ", s1%s
      print *, "  bar = ", s2%s

   end associate asc

   print *, "after associate: "
   print *, "  foo = ", foo%s
   print *, "  bar = ", bar%s

   stop

end program p

Upon execution, the response is:

 before swap:
   foo = foo
   bar = bar
 after swap:
   foo = foo
   bar = bar
 after associate:
   foo = bar
   bar = foo

 


Viewing all articles
Browse latest Browse all 5691

Trending Articles



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