************************************************** J3/02-229r2 Date: August 12 2002 To: J3 From: Aleksandar Donev Reviewed by J3 Interop Subgroup at 162 Subject: Enhanced C_LOC: Pointer Arguments ************************************************** ______________________________________ Summary ______________________________________ We propose a modification of the specification of C_LOC from ISO_C_BINDING to allow associated procedure pointers or associated scalar data pointers of interoperable type and type parameters as an argument. This corrects for the (unjustifiable) lack of this functionality in the current draft. ______________________________________ Motivation ______________________________________ Fortran pointers are not interoperable with C and thus not allowed as arguments to C_LOC. However, allocated allocatables are, in which case C_LOC returns the C address of the storage associated with the allocatable array. It only seems reasonable to allow the same for associated scalar pointers, i.e. C_LOC would return the C address of the target of the pointer. Array pointers should be excluded because the variables they are associated to might not be interoperable with C (for example, be noncontiguous array sections). ______________________________________ Possible alternatives ______________________________________ Note that it is possible for a user to make a wrapper around C_LOC to do what is proposed here in a perfectly conforming way for scalar pointers (but not for array pointers since assumed-shape arrays are not interoperable and cannot be arguments to C_LOC): TYPE(C_PTR) :: c_address INTEGER, POINTER :: variable ALLOCATE(variable) c_address=C_LOC_Integer(variable) ! We cannot do c_address=C_LOC(variable) directly CONTAINS FUNCTION C_LOC_Integer(variable) RESULT(c_address) USE ISO_C_BINDING INTEGER, INTENT(IN), TARGET :: variable ! Must be TARGET TYPE(C_PTR) :: c_address ! C_LOC(variable) c_address=C_LOC(variable) END FUNCTION C_LOC_Integer The big disadvantage of this is that we are forcing the user to write a separate wrapper for each type and kind combination he needs for no reason. This would become particularly painful when interoperable derived types are used, since one cannot make a generic wrapper of C_LOC for all interoperable derived types one might use. ______________________________________ Edits: ______________________________________ ___________________ 382: 20-22 Replace with: Argument. X shall be a procedure that is interoperable, a procedure pointer associated with an interoperable procedure, a variable that has the TARGET attribute and is interoperable, an allocated allocatable variable that has the TARGET attribute and has interoperable type and type parameters, or an associated scalar data pointer that has interoperable type and type parameters. ___________________ ___________________ 382: 24-25 Replace with: Result Value: If X is an procedure that is interoperable, a variable that is interoperable, or an allocatable variable that has interoperable type and type parameters, the result is the value that the C processor returns as the result of applying the unary "&" operator to X, as defined in the C standard, 6.5.3.2. If the argument X is a procedure pointer or a scalar pointer, the result is the value that the C processor returns as the result of applying the unary "&" operator to the target of X. __________________