View Full Version : CVF Compatibility (Mangling, calling convention)
garyscott
02-25-2004, 03:28 PM
Hi,
What are the main things I have to consider to ensure that my CVF DLL is compatible with both CVF and LF95 (compiler switches)? It is simply a wrapper for Win32 API calls. I assume that name mangling is an issue.
tzeis
02-25-2004, 05:43 PM
To avoid mangling conflicts, I suggest using the Visual C calling convention. If you do that, you have solved your mangling conflicts.
Another possible conflict occurs when passing character data. I seem to recall that CVF places the hidden length argument directly after the character variable in the argument list, while LF95 places hidden arguments at the end of the list. If you null terminate the character data and strip the length argument before making the DLL call, you won't have to worry about hidden arguments.
garyscott
02-25-2004, 10:30 PM
Hi,
I guess that would defeat the purpose. I'm trying to isolate the user from having to make Win32 API calls and null terminating strings and writing separate interface blocks. I was hoping for compiler options to change the argument passing scheme to match. I do know that CVF can change to passing length arguments at the end so maybe that would partially work. I'll just have to compare all the compiler options I guess. I thought maybe one or the other had a "do it like other Fortran compiler" option. I really hate the thought of having to produce a different version for LF90, LF95, CVF, Salford FTN77, Salford FTN95, G77, OpenWatcom...Maybe Lahey could implement such an option. It would be sort of like a "cross compiler" that library vendors could use on the Lahey compiler and produce libraries and DLLs compatible with all the other compilers at the touch of a button (whether usable directly by LF95 or not). I'll even send you extra money for that one.
garyscott
02-26-2004, 07:32 PM
Originally posted by garyscott
Hi,
What are the main things I have to consider to ensure that my CVF DLL is compatible with both CVF and LF95 (compiler switches)? It is simply a wrapper for Win32 API calls. I assume that name mangling is an issue.
I had hoped that I could do this all via compiler switches rather than source code modifications for each configuration, but it appears that CVF (probably all I guess) have the ability to produce a precisely tailored library through inline directives. So it seems fairly straightforward (but unnecessarily tedious) to produce an LF95 version of the library. I guess I simply need to understand what the default convention needs to be and apply the appropriate attributes, alias, and compiler string length argument passing convention options. This really needs to be a global selection in addition to the inline directives (sort of like you do for Delphi, VB, etc). That would obviate the need for preprocessor and source code modifications/tailoring in this case (which I would think would be a fairly important need for library vendors). (sorry, I'm new to trying to produce a library for multiple other compilers).
tzeis
02-27-2004, 05:50 AM
It seems like most people producing DLLs for Fortran create separate DLL's for each supported compiler. Whether you try to produce a single DLL that supports both compilers, or create separate DLL's, the result will probably be the code calling the DLL's will be vendor dependent and non portable. The situation is not at all clean cut enough for me to give you a "default" convention, the closest option to what you want is the "-ml msvc" option for Visual C.
If your ultimate goal is to make it easy on the programmer using your libraries, you might consider using a module rather than DLL's. All the WinAPI export directives, function types, structure definitions, defined constants, and your interface procedures can be encapsulated, and you can control how much you want to expose to the end user. You will still have to create vendor dependent versions of the module, but you will be able to hide the non portable uglyness, so the end user can write one piece of code that will work with any compiler.
garyscott
02-27-2004, 01:22 PM
Hi,
I believe I have a solution to produce targeted libraries that makes it fairly easy on me. Once I figure out all the differences, I believe that CVF has enough compiler directive capability to produce virtually any calling convention (with possible exception of full control of stack cleanup, which I haven't studied yet). I believe that I can put all of the ugly compiler directives into an include file and just set a variable at the top of my main to select the correct compiler type (set of directives). That way the only messiness (I hate messing up my source with lots of ugly directives) in my Fortran source will be an include file in each procedure and the resulting library produced will be compatible with the default conventions of the target compiler (my hope anyway, but it looks doable so far). All that work, just to make a freely available library...sheesh.
Thanks
vBulletin® v3.6.8, Copyright ©2000-2010, Jelsoft Enterprises Ltd.