Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
27431 Discussions

Compiler Bug? c_f_procpointer() not accepting procedure pointer in COMMON

ereisch
New Contributor II
207 Views
 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 19.1.3.304.

0 Kudos
3 Replies
Steve_Lionel
Black Belt Retired Employee
196 Views

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.

ereisch
New Contributor II
187 Views

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).

Steve_Lionel
Black Belt Retired Employee
174 Views

Why not use a module variable? COMMON has outlived its usefulness nowadays.

Reply