Both functions here are taking all their arguments by value (which is
the norm in C).
Consequently all arguments in the interface blocks in the Fortran must
be declared to have the VALUE attribute.
(From what you write above, it reads as if you are saying that the
declaration of an argument in one procedure definition in the Fortran
code is somehow bleeding through to another. If that were the case it
would be a compiler bug - each procedure definition in each interface
block has its own scope. Note your code as presented may not be a
sufficient test that a bug like this actually exists - but just in case
- what specific version of gfortran are you using (4.???.???).)
Style ramblings:
Because each procedure has its own scope it also has its own set of
implicit typing rules - in the absence of a specification to the
contrary this is the ye-olde Fortran default of I-M INTEGER, others
REAL. While procedure declarations are small and hence simpler to scan
and check, a mistyped argument name could still occur - so consider
adding IMPLICIT NONE.
Consider also adding argument INTENT's - for a code documentation
benefit at least, let alone the additional opportunities for the
compiler to detect program logic errors, etc.
Future standard revisions could place lots of additional things in
ISO_C_BINDING. If one of those future symbols clashes with a name in
the scope of the USE statement, then your code will no longer be valid
against those future standards. To future proof against such a change
consider adding the ONLY clause to the use statement to only pull in the
things that you really need from that module.
> which must be present, otherwise I'll get 'undefined references'
> at the time of linking.
C++ needs to distinguish at link time between functions with the same
name in source that take parameters (to use the C term) of different
type (differentiate between "overloads"). It does this by "mangling"
(or perhaps "decorating", depending on your taste in names) the linker
name with a compiler specific encoding of the parameter types.
Adding extern "C" turns this off - the linker name for the function will
then be equivalent to what a C compiler would produce for that function
(this is really the nub of the idea of extern "C").
A consequence of this is that you cannot then overload extern "C"
functions in C++.
In Fortran, you can also "overload" procedures through the use of
generics - where one generic may have several specific procedures that
can be distinguished on the type, kind and rank of their arguments. In
this case the mangling of the name of the specific is managed by the
programmer.
INTERFACE DoMagic
PROCEDURE DoMagic_for_integer
PROCEDURE DoMagic_for_real
PROCEDURE DoMagic_for_character
END INTERFACE DoMagic