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

More C interopability: exporting overloaded procedures

eos_pengwern
Beginner
407 Views
How does one go about exporting overloaded, C-interoperable procedures from a DLL?

When programming in C, it's straightforward: just export each individual overloaded procedure. It's also straightforward when programming in Fortran for calling from the same Fortran program: use an interface block at the head of the module, viz:

[cpp]module gubbins

    interface foo
        module procedure sfoo, dfoo
    end interface

contains

    subroutine sfoo(x, bar)

        real(kind(1e0)), intent(in) :: x
        real(kind(1e0)), intent(out) :: bar
        .
        .
    end subroutine sfoo

    subroutine dfoo(x, bar)

        real(kind(1d0)), intent(in) :: x
        real(kind(1d0)), intent(out) :: bar
        .
        .
    end subroutine sfoo

end module gubbins[/cpp]

...and so on. But what if I want to export these functions to a DLL, which will be loaded from a program written in C? I'd like the header file to look like:

[cpp]void foo(float x, float bar);
void foo(double x, double bar);[/cpp]

... but how might I bring this about? At the moment I'm not quite sure where to start. Should the !DEC$ DELLEXPORT directives be placed in the procedures, in the interface block, or somewhere else? Is this even possible?
0 Kudos
2 Replies
Steven_L_Intel1
Employee
408 Views

The DLLEXPORT directives go in the procedures - always. Of course, C can't resolve the generic reference, so you'll have to call the specific procedure name from C.
0 Kudos
eos_pengwern
Beginner
408 Views

The DLLEXPORT directives go in the procedures - always. Of course, C can't resolve the generic reference, so you'll have to call the specific procedure name from C.

Thanks Steve,

That's what I'd feared, but now I know,I can avoid wasting time trying to get around it!
0 Kudos
Reply