Help on Interface statement?

13 views
Skip to first unread message

Ray

unread,
Jul 9, 2009, 11:49:41 AM7/9/09
to gg95
Dear All:

I am managing an old Fortran Project. I found a sentence like
this:

INTERFACE TO INTEGER*4 FUNCTION SHUTDOWN[DLLEXPORT, STDCALL]
()
END

Is it equal to:

INTERFACE
INTEGER(4) FUNCTION SHUTDOWN
!DEC$ATTRIBUTES DLLEXPORT, STDCALL :: SHUTDOWN
END FUNCTION
END INTERFACE

Thanks.

Tobias Burnus

unread,
Jul 27, 2009, 4:46:15 AM7/27/09
to gg95
On 9 Jul., 11:49, Ray <shangshu....@gmail.com> wrote:
>          I am managing an old Fortran Project. I found a sentence like
> this:
>          INTERFACE TO INTEGER*4 FUNCTION SHUTDOWN[DLLEXPORT, STDCALL]
>          END
>
>    Is it equal to:
>
>          INTERFACE
>          INTEGER(4) FUNCTION SHUTDOWN
> !DEC$ATTRIBUTES DLLEXPORT, STDCALL :: SHUTDOWN
>          END FUNCTION
>          END INTERFACE

If you do not use a 32bit Windows, you can ignore the [DLLEXPORT,
STDCALL] part as well as the !DEC$ ATTRIBUTES directive. The "!DEC$"
lines are ignored in all cases (comment lines) while you need to
remove/comment the [...].

If you are just curious about the !DEC$, have a look at the Intel
Fortran Compiler documentation (or see below).

* * *

On Windows (except for the extremely rare 64bit Windows): By default
in C (and Fortran) the function arguments are placed on the stack and
the invoking procedure removes (pops) it from the stack (this is also
called "CDECL"). Another possibility - I think started by Pascal? - is
that the called procedure clears the stack before it returns - for
some reasons this is called STDCALL. Most but not all (system) DLLs on
Windows use STDCALL; additionally on Windows the symbol name for
STDCALL are decorated by a suffix such as @12 where the number is the
byte-size of the argument. (For completeness, there is also FASTCALL
which passes arguments via CPU registers - well, at least some. That
is faster for small arguments and I think, e.g., the Linux kernel uses
it. Unless one needs to access/create Windows DLLs, there is little
reason to use anything but the default CDECL.)

Thus if you really need STDCALL with g95, you have essentially two
choices:
a) Write a wrapper in C
b) Compile with -mrtd and add the @<n> manual in the BIND(C,name=....)
but note that -mrtd this affects all procedures in a file - for both
calls and function declarations.

Alternative (c): Convince Andy to add support for such attributes. GNU
Fortran (gfortran) 4.5 supports them via !GCC$, cf.
http://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-Compiler-Directives.html
(Using gfortran would be alternative (d). In case Andy wants to
implement the same in g95, I can point him to the gfortran patches
which might make implementing a bit faster.)

Tobias
Disclaimer: I am a gfortran developer and I added the STDCALL support
to gfortran.
Reply all
Reply to author
Forward
0 new messages