c_loc followed by c_f_pointer: interoperable argument?

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

According the F2003 and F2008 language specifications, the shape argument is required if the fptr argument is an array. Below is from the language spec:

SHAPE
(optional)
shall be of type integer and rank one. It is an INTENT(IN) argument.
SHAPE shall be present if and only if FPTR is an array; its size shall be
equal to the rank of FPTR

Add the third rank argument and it should compile.

dave

Many thanks Dave, this fixed the problem.

The phrasing of the error message (“keyword argument fptr”) led me to concentrate too much on the type of the fptr argument. I’m only just starting out with pgfortran & I guess I have to get used to things like this.