3 ! Contributed by: Vladimir Fuka <vladimir.fuka@gmail.com>
8 class(*), allocatable, target :: a(:)
10 call add_element_poly(a,e)
11 if (size(a) /= 1) STOP 1
12 call add_element_poly(a,e)
13 if (size(a) /= 2) STOP 2
16 if (any (a /= [ 1, 1])) STOP 3
19 subroutine add_element_poly(a,e)
21 class(*),allocatable,intent(inout),target :: a(:)
22 class(*),intent(in),target :: e
23 class(*),allocatable,target :: tmp(:)
27 function memcpy(dest,src,n) bind(C,name="memcpy") result(res)
30 integer(c_intptr_t),value :: dest
31 integer(c_intptr_t),value :: src
32 integer(c_size_t),value :: n
36 if (.not.allocated(a)) then
37 allocate(a(1), source=e)
39 allocate(tmp(size(a)),source=a)
41 allocate(a(size(tmp)+1),mold=e)
42 dummy = memcpy(loc(a(1)),loc(tmp),sizeof(tmp))
43 dummy = memcpy(loc(a(size(tmp)+1)),loc(e),sizeof(e))