- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I have some Fortran 77 sources file that I'd like to compile as a DLL so I can call functions from an external GUI to interact with Fortran DLLs.
I compiled the DLL with the latest version of the Intel compiler, and apparently the DLL is generated correctly and called from the external GUI (in C#).
But I've noticed a behavioral issue with the DLL because it doesn't return the expected value of a variable. The problem isn't related to the source file, since compiling the .for file in Visual Studio returns the correct values.
I believe the problem is in the compiler settings or in the directives inserted in the .for file; can anyone help me resolve the issue?
Thanks,
Valerio
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok I report the extract of my two files .for and .cs:
file .for 77 (two subroutine)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've solved using /Qsave parameter during the compilation, this permits to allocate the local variables into the memory without pass they into the stack.
cheers!
V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>I've solved using /Qsave parameter during the compilation
Do you intend to (later) call your DLL from a multi-threaded process?
If so, then the /Qsave may be problematic.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
yes I'm using multi-thread but each subroutine with /Qsave is called from only one dedicated thread so local variables should not be at risk of being overwritten.
Valerio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why might I have hidden problems? The Fortran source is secure and tested, including local variables. Even uninitialized variables will be assigned a value, the important is that the value is not lost.. or not?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok that's correct.
Just for info I'm using CallingConvention "Cdecl" C declaration so the caller (my C# GUI) clear the stack; in the file .for77 use this directive -> !DEC$ ATTRIBUTES DLLEXPORT :: name_of _subroutine
It's correct use this or better STDCALL? I honestly don't know which one is better to use. I only understood that they must be declared in the same way to correctly manage stack cleaning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as I know,
with cdecl convention, arguments are pushed to the stack before calling the procedure who doesn't have to know the actual size of arguments to return correctly. That allows variable number of arguments.
with stdcall convention,, it's the opposite so the called procedure use the declared size of arguments to get the return address from the stack. It's why the arguments size is added to the procedure name to avoid mismatches. Optional arguments must be declared and pushed as null pointer if absent to preserve the argument size.
cdecl guaranties that the procedure will return correctly even if arguments number or size is incorrect may be silently.
stdcall will crash if arguments number or size is incorrect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okk thk for your advice..I'll use Cdecl convention..;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>I've solved using /Qsave parameter during the compilation
or seond sol is this

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