SUBROUTINE PROCPTR_COMMON (C_FCN) BIND(C) C C USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE C C TYPE(C_FUNPTR), VALUE, INTENT(IN) :: C_FCN PROCEDURE(), POINTER :: F_FCN COMMON/FOO/F_FCN C CALL C_F_PROCPOINTER ( C_FCN, F_FCN ) END
In the above code block, I would expect this to compile fine, but I get an error that F_FCN is an undefined type. However, if you comment-out the COMMON line, it compiles fine. Is this a compiler bug, or illegal use of Fortran? No special compiler flags are needed to bring about the issue.
Using ifort version 22.214.171.1244.
Not valid Fortran.
C8119 (R874) A common-block-object shall not be a dummy argument, a function result, an allocatable variable, a derived-type object with an ultimate component that is allocatable, a procedure pointer, an automatic data object, a variable with the BIND attribute, an unlimited polymorphic pointer, or a coarray.
The error message could be better, for sure. I would consider it a bug that the compiler did not give an error message on the COMMON statement.
Hmm....I was afraid of that. I'm trying to think of how to get a function pointer from one portion of my program to another (very distant) routine at a point much later, and am not having much luck. I tried storing the type(c_funptr) in the common block, which seems to work, but the copy of the c_funptr from the routine that receives it as an argument to the common block variable doesn't seem to be happening correctly. I tried both "a = b" and "a => b", but the former doesn't copy the contents and the latter is illegal (because it isn't a TARGET).