10.07.2015 Views

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Interoperability with CSyntaxc_f_pointer (cptr, fptr [,shape] )TypesubroutineDescriptionc_f_pointer assigns the target, cptr, to the <strong>Fortran</strong> pointer, fptr, and specifies its shape.‣ cptr is a scalar of the type C_PTR with INTENT(IN). Its value is one of the following:‣ the C address of an interoperable data entityIf cptr is the C address of a <strong>Fortran</strong> variable, the <strong>Fortran</strong> variable must have the targetattribute.‣ the result of a reference to c_loc with a non-interoperable argument.‣ fptr is is a procedure pointer with INTENT(OUT).‣ If cptr is the C address of an interoperable data entity, then fptr must be a datapointer of the type and type parameters of the entity. It becomes pointer associated withthe target of cptr.‣ If cptr was returned by a call of c_loc with a non-interoperable argument x, thenfptr must be a nonpolymorphic scalar pointer of the type and type parameters of x.x, or its target if it is a pointer, must not have been deallocated or become undefined due toexecution of a return or end statement.fptr is associated with x or its target.‣ shape is an optional argument that is a rank-one array of type INTEGER withINTENT(IN). shape is present if and only if fptr is an array. <strong>The</strong> size must be equal tothe rank of fptr; each lower bound is assumed to be 1.Exampleprogram mainuse iso_c_bindingimplicit noneinterfacesubroutine my_routine(p) bind(c,name='myC_func')import :: c_ptrtype(c_ptr), intent(out) :: pend subroutineend interfacetype(c_ptr) :: cptrreal,pointer :: a(:)call my_routine(cptr)call c_f_pointer(cptr, a, [12])end program main<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!