The error in the program is that you’re using “BIND(C)” on a TYPE. Bind(C) is only allowed on procedures and external global variables. Changing "TYPE, bind(C) :: info_t " to “TYPE :: info_t” will allow it compile.
The compiler error is not detecting this syntax error and instead generating multiple declarations for info_t. I have submitted a problem report (TPR#17165) to detect this error and give a better message.
I’m a bit confused what you mean, I’m following the Fortran 2003 standard, if you look at section 15.2.3 Interoperability of derived types and C struct types:
2 A Fortran derived type is interoperable if it has the BIND attribute.
And it clearly shows in NOTE 15.14 the convention I used:
USE, INTRINSIC :: ISO_C_BINDING
TYPE, BIND(C) :: MYFTYPE
INTEGER(C_INT) :: I, J
REAL(C_FLOAT) :: S
END TYPE MYFTYPE
The suggestion you make is not standard compatable and breaks on other compilers.
If the type declaration is moved to the module scope the code compiles.
MODULE liter_cb_mod
USE ISO_C_BINDING
TYPE, BIND(C) :: MYFTYPE
INTEGER(C_INT) :: I, J
REAL(C_FLOAT) :: S
END TYPE MYFTYPE
CONTAINS
FUNCTION liter_cb() bind(C)
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(c_int) liter_cb
TYPE(MYFTYPE) :: link_info
liter_cb = 0
END FUNCTION liter_cb
END MODULE liter_cb_mod
There was a discussion about the matter in comp.lang.fortran under the topic
“BIND(C) functions in a module error” as to the source of the problem if interested.
My sincere apologies. I had missed this section and agree that this is valid code.
After discussing the issue with our lead compiler Architect, we also agree that the error is compiler issue that appears to only occur in this scenario. I’ve updated TPR#17165 with this information and we will assign a compiler engineer to investigate further.