Inquiry Intrinsic Function (Generic): Returns the internal address of a storage item. This function cannot be passed as an actual argument.
Syntax
result = LOC (x)
x
(Input) Is a variable, an array or record field reference, a procedure, or a constant; it can be of any data type. It must not be the name of a statement function. If it is a pointer, it must be defined and associated with a target.
Results
The result type is INTEGER(4) on IA-32 architecture; INTEGER(8) on Intel® 64 and IA-64 architectures. The value of the result represents the address of the data object or, in the case of pointers, the address of its associated target. If the argument is not valid, the result is undefined.
This function performs the same function as the %LOC built-in function.
Example
! Mixed language example passing Integer Pointer to C
! Fortran main program
INTERFACE
SUBROUTINE Ptr_Sub (p)
!DEC$ ATTRIBUTES C, ALIAS:'_Ptr_Sub' :: Ptr_Sub
INTEGER p
END SUBROUTINE Ptr_Sub
END INTERFACE
REAL A[10], VAR[10]
POINTER (p, VAR) ! VAR is the pointer-based
! variable, p is the integer
! pointer
p = LOC(A)
CALL Ptr_Sub (p)
WRITE(*,*) "A(4) = ", A(4)
END
! C subprogram
void Ptr_Sub (int *p)
{
float a[10];
a[3] = 23.5;
*p = a;
}