Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Conversion from CVF to IVF, called C function not the same return

Wesley_G_
Beginner
795 Views
I have a program that I am converting from CVF to IVF. This is a C program that calls a FORTRAN function. In addition, the FORTRAN function calls a couple of C functions. On one of these, the return value from the C function being called by FORTRAN does not have the same value as when this was done with CVF. I declae the C function as int _stdcall xxx_()
I'm not sure what settings have changed.
Any ideas.
Thx,
Wes
0 Kudos
8 Replies
Steven_L_Intel1
Employee
795 Views
Is this a Visual Studio project that was converted from CVF using the "Extract Compaq Visual Fortran Project Items" tool? On the project property page Fortran..External Procedures, what is the calling convention?
0 Kudos
Wesley_G_
Beginner
795 Views

It is a project that was "extracted". The calling convention is CVF.

W

0 Kudos
Steven_L_Intel1
Employee
795 Views
Nothing comes to mind right away. When you run it in the debugger and step through the Fortran code, is the return value set to what you expect? Could it be that your program relies on an uninitialized variable?
0 Kudos
Wesley_G_
Beginner
795 Views

The return code is being set properly in the C function, but once it gets to FORTRAN it is not set properly.

0 Kudos
Steven_L_Intel1
Employee
795 Views
Make sure that the C function's name is declared properly in the caller (with the right type.)

If you can't solve the problem, send a test case to Intel Premier Support.
0 Kudos
Wesley_G_
Beginner
795 Views

I've been reading about declaring the functions, etc. Do I need to declare things as "C" ?? I saw that in one of the help files.

Is there a document that explains the differences between CVF and IVF when using mixed languages??

Thx,

W

0 Kudos
Steven_L_Intel1
Employee
795 Views
If you're compiling with the calling convention set to CVF, there are no differences. You'll want to read Migrating from CVF to Intel Visual Fortran.

As with CVF, you would need to declare the C functions with the C attribute - unless they were defined as __stdcall in the C code. (If you were not using /iface:cvf, you could omit that in some cases.) When I mentioned declaring, I meant datatype, though your problem does sound like a symptom of mismatched calling conventions.

You should also read the chapter on mixed-language programming in the Building Applications manual, though it is really much the same as for CVF.
0 Kudos
Intel_C_Intel
Employee
795 Views
Hello,
When we did the transition CVF -> IVF we manually rewrote the interfaces between C and Fortran to enable usage of the new default settings. That is we used __cdecl on theC-side and used the new defaultcref on the Fortran side. The reason we did this is that we think that it is convenient to have exactly the same number of function/subroutine arguments on both sides. This was not the case peviously where strings passed resulted an extra integer on the C-side - the length of the string.
In the long run this approach may be the best as it thus clearly reduces the probability of bugs related to mixed language issues.
Lars Petter
0 Kudos
Reply