c_loc

Date:

09-08-2014

NAME

c_loc - Returns the C address of an argument

SYNOPSIS

result = C_LOC(X)

IMPLEMENTATION

Cray Linux Environment (CLE)

STANDARDS

Fortran

DESCRIPTION

The argument must have the POINTER or TARGET attribute. It must not be a coindexed object. It must be either a variable with interoperable type and kind type parameters, or be a nonpolymorphic variable with no length type parameters. If it is allocatable, it must be allocated. If it is a pointer, it must be associated. If it is an array, it must be contiguous and have nonzero size. It must not be a zero-length string.

RETURN VALUES

A scalar value of the type c_ptr indicating the C address of the argument.

EXAMPLES

The following example shows how to pass the address of a Fortran array to a C function with prototype void c_function(void *A); :

use,intrinsic :: iso_c_binding
interface
       subroutine c_function(p) bind(c)
          use,intrinsic :: iso_c_binding
          type(c_ptr), value :: p  ! Must have the value attribute
       end subroutine
end interface
real, target, dimension(10) :: A
type(c_ptr) :: c                   ! The variable to pass the address of A
c = c_loc(A)                       ! Get the address of A
call c_function(c)                 ! Call the C function