Skip to content

Instantly share code, notes, and snippets.

@nicolasbock
Created January 29, 2015 00:59
Show Gist options
  • Save nicolasbock/03841ce79f7148b4ff30 to your computer and use it in GitHub Desktop.
Save nicolasbock/03841ce79f7148b4ff30 to your computer and use it in GitHub Desktop.
using a source when allocating in Fortran
program test
type :: a_t
integer, pointer :: i => null()
end type a_t
type(a_t), pointer :: a, b
nullify(a, b)
allocate(a)
allocate(a%i)
a%i = 1
allocate(b, source=a)
if(associated(a, b)) then
write(*,*) "a and b point to the same target"
endif
if(associated(a%i, b%i)) then
write(*,*) "a%i and b%i point to the same target"
endif
end program test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment