Intel® Fortran integer pointers (also known as Cray*-style pointers) are not the same as Fortran 90 pointers, but are instead like C pointers. On systems based on IA-32 architecture, integer pointers are 4-byte INTEGER quantities. On systems based on Intel® 64 architecture, integer pointers are 8-byte INTEGER quantities.
When passing an integer pointer to a routine written in another language:
The argument should be declared in the non-Fortran routine as a pointer of the appropriate data type.
The argument passed from the Fortran routine should be the integer pointer name, not the pointee name.
Fortran main program:
! Fortran main program. INTERFACE SUBROUTINE Ptr_Sub (p) !DEC$ ATTRIBUTES C, DECORATE, ALIAS:'Ptr_Sub' :: Ptr_Sub INTEGER (KIND=INT_PTR_KIND()) p END SUBROUTINE Ptr_Sub END INTERFACE REAL A(10), VAR(10) POINTER (p, VAR) ! VAR is the pointee ! p is the integer pointer p = LOC(A) CALL Ptr_Sub (p) WRITE(*,*) 'A(4) = ', A(4) END !
On systems using Intel® 64 architecture, the declaration for p in the INTERFACE block is equivalent to INTEGER(8) p and on systems using IA-32 architecture, it is equivalent to INTEGER (4) p.
C subprogram:
//C subprogram void Ptr_Sub (float *p) { p[3] = 23.5; }
When the main Fortran program and C function are built and executed, the following output appears:
A(4) = 23.50000
When receiving a pointer from a routine written in another language:
The argument should be declared in the non-Fortran routine as a pointer of the appropriate data type and passed as usual.
The argument received by the Fortran routine should be declared as an integer pointer name and the POINTER statement should associate it with a pointee variable of the appropriate data type (matching the data type of the passing routine). When inside the Fortran routine, use the pointee variable to set and access what the pointer points to.
Fortran subroutine:
! Fortran subroutine. SUBROUTINE Iptr_Sub (p) !DEC$ ATTRIBUTES C, DECORATE, ALIAS:'Iptr_Sub' :: Iptr_Sub INTEGER (KIND=INT_PTR_KIND()) p integer VAR(10) POINTER (p, VAR) OPEN (8, FILE='STAT.DAT') READ (8, *) VAR(4) ! Read from file and store the ! fourth element of VAR END SUBROUTINE Iptr_Sub ! //C main program extern void Iptr_Sub(int *p); main ( void )
C Main Program:
//C main program extern void Iptr_Sub(int *p); main ( void ) { int a[10]; Iptr_Sub (&a[0]); printf("a[3] = %i\n", a[3]); }
When the main C program and Fortran subroutine are built and executed, the following output appears if the STAT.DAT file contains 4:
a[3] = 4
Copyright © 1996-2010, Intel Corporation. All rights reserved.