- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have another question which maybe seems to be really stupid to you. But because I have not much experince with Fortran and a google search as well as a search here could not answer my question I have to start this thread.
Are the !DEC$ATTRIBUTES "directives" compilerindependent or not ?
Because my program should be compiler independent so I have to use "directives" whichare supportedby everycompiler.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The actual Fortran 2003 standard introduced few concepts which should enhance portability; the most important are VALUE attribute and ISO_C_BINDING module, used for interfacing with C and compatible languages. ISO_C_BINDING covers most of !DEC$ATTRIBUTES semantics, as well as C pointer (de)referencing (supplement for non-portable "Cray" pointers). However, those are not yet implemented in IVF :-(. I'm not sure about the exact list, but I think g95 and IBM's XLF did implement it (maybe also Lahey).
So, there's lot to be desired in this field... As a solace, !DEC$ directives are ignored by other compilers, so you might get away by other means.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
So when I understand you right, than the way to call DLL routines for example differs fromcompilerto compiler.
I will refer to my other thread.Which is aboutcalling routines in a C++ DLL from a Fortran main. There I have a interface like this
interface
subroutine asdf()
!DEC$ATTRIBUTES C, DLLIMPORT, ALIAS: "_asdf" :: asdf
end subroutine asdf
end interface
So when I want to compile it with CVF or IVF than the code is correct, but when I try to build it with another compiler than it might not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hmm no answers :-/
So then I willask my question in other words.
Is it possible to useroutines fromDLLs without the !DEC$ATTRIBUTES command ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is compiler-dependent are calling conventions (cdecl/stdcall), external name mangling (uppercase/lowercase, trailing/leading underscore), means to pass character arguments etc. Note that people do get by interfacing with C even with compilers without semantic equivalents of !DEC$ATTRIBUTES; there are limitations though. For example, there is no language-defined way to call a C procedure with a CamelCase name, or with STDCALL calling convention. Fortunately, IVF defaults match those of most other compilers (CVF's didn't).
As for e.g. DLLEXPORT, it can also be worked around by supplying a .def file with the contents:
EXPORTS
_MyFortranRoutine=_MYFORTRANROUTINE
_MyOtherRoutine=_MYOTHERROUTINE
and including it into the project (it will be given to the linker). It will export symbols "_MyFortranRoutine" etc. which can be referenced from C as
extern "C" void MyFortranRoutine(...)
I think that a similar trick can be performed in reverse direction, i.e. with calling C dlls routines in lowercase or mixed-case (create a .lib file from .def file (instead of using one generated by C compiler ) using LIB command-line tool, then insert that lib file into the Fortran project). Didn't do that myself though. That avoids the need for ALIAS attribute.
See:
http://msdn2.microsoft.com/en-us/library/d91k01sh.aspx
http://msdn2.microsoft.com/en-us/library/f0z8kac4.aspx

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page