silverfrost Site Admin
Joined: 29 Nov 2006 Posts: 191 Location: Manchester
|
Posted: Sun Sep 05, 2004 6:46 pm Post subject: When to use C_EXTERNAL and STDCALL |
|
|
When calling functions in libraries created in other languages, you must specify which calling convention is used. The calling convention specifies whether the function name is 'decorated' and how the function arguments are dealt with. The two main calling conventions you will need to know about are cdecl (specified by C_EXTERNAL) and stdcall (specified by STDCALL)).
If you are using a function library built by someone else (e.g. the Win32 API) you will be told which calling convention to use (in the case of the Win32 API, it is stdcall). If you are building your own function library, then you must specify the calling convention yourself. In C/C++ you can do this using extern "C" to specify the C calling convention, or __stdcall to specify the stdcall calling convention. For example:
Code: |
void sub(); // declares a function that cannot be called from fortran
extern "C" void sub(); // declares a function that can be called from fortran using C_EXTERNAL
void __stdcall sub(); // declares a function that can be called from fortran using STDCALL
|
|
|