Re: BIND(C) EXPORT / IMPORT of Fortran variables



Arjen Markus wrote:
On 14 mrt, 09:37, "FX" <coud...@xxxxxxxxxxxxx> wrote:
I don't think the symbol is required to be named "foo", exactly
I think it is: by default it is the lowercase version of the name of
the Fortran variable
No, the symbols has to have the same name than the C compiler would give
to "foo". Systems have different rules for symbol names, for example
MacOS prefixes them with an underscore:

$ cat a.f90
module globals
use iso_c_binding
integer(c_int), bind(c) :: foo
end module globals
$ gfortran -c a.f90 && nm a.o
00000010 C _foo
$ cat b.c
extern int foo;
int main(void){ foo = 0; return 0;}
$ gcc -c b.c && nm b.o
00000024 S ___i686.get_pc_thunk.cx
U _foo
00000000 T _main

--
FX

But that is a "decoration" that is not visible on the C side, is it?
Just like Fortran names often get an underscore appended or get
converted to uppercase. Those name manglings are visible to the linker
and the compiler, they have nothing to do with the source code an
ordinary programmer writes.

(Or maybe I have misinterpreted the question - that happens ;))

We're talking about what appears in the object file, not what's visible to either the Fortran side or the C side.
.



Relevant Pages

  • Re: Fortran 2003: Procedures in assignments
    ... features of Fortran 2003. ... procedure:: foo ... Could the problem be because the compiler doesn't fully ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ...
    (comp.lang.fortran)
  • Fortran 2003: Procedures in assignments
    ... features of Fortran 2003. ... procedure:: foo ... Could the problem be because the compiler doesn't fully ... m dot r dot karatay -at- domain as above ...
    (comp.lang.fortran)
  • Allocatable components + mixed-language
    ... END TYPE Foo ... The tricky bit is to include the Fortran code into a library that is ... Allocate memory for Foo, ...
    (comp.lang.fortran)
  • Re: Incorrect values calling F from C
    ... problem that I have when using iso_c_binding, and calling Fortran ... END TYPE foo ... Returning 'struct' types in C has long been an area of implementation ... Most compilers pass the address of a temporary as an ...
    (comp.lang.fortran)
  • Re: Fortran calls a C function that returns a struct
    ... | C structs and Fortran derived types do not have much in common, ... TYPEFUNCTION Foo() ... struct Whatever Foo; ... void FooWrapper(Whatever* pWh) ...
    (comp.lang.fortran)