Hello,
Pgfortran 11.9 does not like the following code, which ifort thinks is OK and I believe to be F2003 compliant. I am trying to understand what the problem is.
module testmod
TYPE HEADER_RECORD
PRIVATE
INTEGER :: INDEX_POSITION
INTEGER :: BYTE_POSITION
INTEGER(KIND=1), POINTER :: BYTE_ARRAY(:) => NULL()
END TYPE HEADER_RECORD
contains
SUBROUTINE HEADER_RECORD_WRITE_INTG(SELF,VALUE)
USE ISO_C_BINDING
IMPLICIT NONE
! Arguments
CLASS(HEADER_RECORD), INTENT(INOUT) :: SELF
INTEGER(KIND=4), TARGET, INTENT(IN) :: VALUE
! Private variables
INTEGER(KIND=1), POINTER :: BYTE_PTR(:)
TYPE(C_PTR) :: CPTR
! Start work
! Prepare a byte pointer to the value
CPTR = C_LOC(VALUE)
CALL C_F_POINTER(CPTR,BYTE_PTR)
! Copy the bytes over
SELF%BYTE_ARRAY(SELF%BYTE_POSITION:SELF%BYTE_POSITION+3) = BYTE_PTR(1:4)
! Nullify pointers
NULLIFY(BYTE_PTR)
END SUBROUTINE HEADER_RECORD_WRITE_INTG
end module
From reading the Portland Fortran Reference (page 322, c_f_pointer doc), I see that
If cptr was returned by a call of c_loc with a non-interoperable argument x, then fptr must be a nonpolymorphic scalar pointer of the type and type parameters of x
In the case above, it seems to me that the “VALUE” variable, being an INTEGER, should be interoperable, so that the above restriction should not apply. Am I missing something?
Why is pgfortran giving me this error?
PGF90-S-0074-Illegal number or type of arguments to c_f_pointer - keyword argument fptr (test.f90: 25)
Thanks for your help