To: X3J3

From: /interop

Subject: definition of c_loc

 

Ref: 98-239 (and various predecessors) promised a "loc" function.

 

Specification

When interoperating with a C facility, it is often necessary to pass the "address" of an entity (data or procedure). A "loc" function has long been part of many Fortran processors to provide this functionality. In keeping with the style of the ISO_C_BINDING module, a C_LOC function is defined.

 

Syntax

C_LOC(x)

Description Provide the "C address".

Class Inquiry

Argument x shall be either a variable that has the TARGET attribute and interoperates with some C type or a procedure that has the BIND(C) attribute. It shall not be an array pointer, an assumed-shape array, or an array section.

 

J3 Discussion note: does not include : common block, namelist group, pdt variable, enum decls, named constants

 

Result characteristics a scalar of type C_PTR

Result Value The value that the target C processor returns as the result of the unary "&" operator, as defined in C9x, 6.5.3.2.

 

Example USE ISO_C_BINDING

real, TARGET,dimension (10) :: a

Type(c_ptr) :: c

c = c_loc(a)

call foo(c) ! foo is a c routine

 

Semantics

C_LOC is a function, defined in the intrinsic module ISO_C, which returns the value that the target C processor returns as the result of the unary "&" operator, as defined in C9x 6.5.3.2.

 

Edits

 

Change 16.1 "The ISO_C_TYPES" to "The ISO_C_BINDING" this change should propagate as needed. Subgroup found only references at 377: 28 and 377:33.

 

Add C_LOC to the list of provided functions, at the end of 16.1 (after 377:32). Also add "The inquiry function C_LOC() (16.2.3) is also provided.

 

Add a new section 16.2.3, entitled "C_LOC The C address operator".

Add the following introductory text:

 

C interfaces are primarily defined in terms of "addresses". C_LOC is provided so that Fortran applications can determine the appropriate value to use in calling C facilities.

 

Add the syntax description above into the document at "this" point.