Alex van der Spek wrpte:
> No experience at all with gfortran. I have relied on MS PowerStation 4
> for the last 15 years or so. With that compiler I could create a DLL
> (not SO obviously) and have control over which routines are to be
> exported and which not, the calling convention (C or pascal) and the
> passing by value or passing by reference. An example is below:
>
> FUNCTION FZAIRY(ZR, ZI, ID, KODE, AIR, AII, NZ)
> *RESULT(IERR)
> !MS$ATTRIBUTES DLLEXPORT :: FZAIRY
> !MS$ATTRIBUTES STDCALL :: FZAIRY
> !MS$ATTRIBUTES VALUE :: ZR, ZI, ID, KODE
> !MS$ATTRIBUTES REFERENCE :: AIR, AII, NZ
> DOUBLE PRECISION ZR, ZI, AIR, AII
> INTEGER KODE, ID, NZ, IERR
> CALL ZAIRY(ZR, ZI, ID, KODE, AIR, AII, NZ, IERR)
> RETURN
> END
>
> Most of the time I have old F77 type FORTRAN. The call to ZAIRY is to a
> netlib routine from Donald Amos. How would the equivalent look like for
> gfortran?
Well, DLLEXPORT and STDCALL are handled via "!GCC$" instead of "!MS$";
REFERENCE is the default.
VALUE and the naming of the function � as seen by the C program � is
handled in gfortran via Fortan 2004's C interoperability support.
Hence, the equivalent to your function should be something like:
function fzairy (zr, zi, id, kode, air, aii, nz) result(ierr) BIND(C)
!GCC$ attributes dllexport, stdcall :: fzairy
double precision, VALUE :: zr, zi
integer, VALUE :: id, kode
double precision :: air, aii
integer :: nz, ierr
CALL ZAIRY(ZR, ZI, ID, KODE, AIR, AII, NZ, IERR)
end function fzairy
should be equivalent.
BIND(C) and VALUE are standard Fortran 2003 features � and dllexport and
stdcall you already know.
See
http://gcc.gnu.org/onlinedocs/gfortran/Mixed_002dLanguage-Programming.html
The first section is about C interoperability between C and Fortran
using C Fortran 2003's C binding; the second section is about !GCC$.
(The naming of the function is handled via BIND(C, name="something"); on
32bit Windows, gfortran automatically adds a leading underscore for
CDECL and a tailing "@" followed by the number of bytes on the stack for
STDCALL. On 64bit Windows, I think basically everything uses CDECL.)
Tobias