Compaq Fortran (integer) pointers are not the same as Fortran 90 pointers, but are instead like C pointers. On ia32 systems, Compaq Fortran pointers are 4-byte INTEGER quantities. On ia64 systems, Compaq Fortran pointers are 8-byte INTEGER quantities.
When passing a Compaq Fortran pointer to a routine written in another language:
! 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 int.
p = LOC(A)
CALL Ptr_Sub (p)
WRITE(*,*) 'A(4) = ', A(4)
END
!
//C subprogram
void Ptr_Sub (float *p)
{
p[3] = 23.5;
}
On ia64 systems, the alias name for Ptr_Sub
should not have a leading
underscore, as follows:
!DEC$ ATTRIBUTES C, ALIAS:'Ptr_Sub' :: Ptr_Sub
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:
For example, on ia32 systems:
! Fortran subroutine.
SUBROUTINE Iptr_Sub (p)
!DEC$ ATTRIBUTES C, ALIAS:'_Iptr_Sub' :: Iptr_Sub
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 )
{
int a[10];
Iptr_Sub (&a[0]);
printf("a[3] = %i\n", a[3]);
}
Iptr_Sub
should not have a leading
underscore, as follows:
!DEC$ ATTRIBUTES C, ALIAS:'Iptr_Sub' :: Iptr_Sub
a[3] = 4