Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

void _FORTRAN

Gabriella_Gaeta
Beginner
656 Views
Hi all!
could anyone help with this problem?
I have an old file with the following function call:

extern "C"
{

void _fortran cstress(LONG *, LONG *);

...

I read the expression _fortran is obsolete.
How can I replace it??
Thanks in advance for your kind response.

Cheers,
Gabri
0 Kudos
6 Replies
TimP
Honored Contributor III
656 Views
If you are using a Fortran which supports ISO C interoperability with your C compiler, as all currently supported products do, you don't need the fortran keyword. You do need to declare the arguments on the Fortran side consistent whether whatever you have defined LONG to be, e.g.
use iso_c_binding
...
c_long arg1,arg2
...
cstress(arg1,arg2)
(passed by reference by default, or you can make it explicit with pointers)
For example, Intel ifort Windows interoperates with MSVC++ and Intel C++; Intel linux ifort and gfortran inter-operate with g++ compatible compilers including icpc.
0 Kudos
JenniferJ
Moderator
656 Views
Are you using Intel Visual Fortran for the Fotran code? how is your Fortran code compiled? did you use /iface option?

Depending on it, you can change the _fortran to __cdecl or __stdcal. Try "__stdcall" first.

The Intel Fortran compiler documentation contains a big part about how to develop/build mix-language application. Please refer to that for complete information.

Jennifer
0 Kudos
Gabriella_Gaeta
Beginner
656 Views
Thanxs for your answers.
Actually, I'm compiling my code (in mixing languages c++ and fortran) using bith Intel compilers for Mac-OS.

I've already tried (following the intel documentation) with __stdcall but the compiler seems to not recognize the command.
Now I also tried with __cdecl but it says:
incomplete type is not allowed

The original piece of the call form cpp file is the following:

extern "C" { void _fortran cstress( _DOUBLE AT, _DOUBLE ADelT) ....



Suggestions?
Thanks
Gabriella


0 Kudos
TimP
Honored Contributor III
656 Views
__stdcall and __cdecl are specific to Windows (the former relevant to Windows of 10 years ago, the latter understood by default by recent compilers for Windows). There is no reason to attempt their use with non-Windows OS.
0 Kudos
Gabriella_Gaeta
Beginner
656 Views
That's true.

And what should I use in mac OS?
0 Kudos
mecej4
Honored Contributor III
656 Views
There is an entire chapter "Programming With Mixed Languages" in the Intel Fortran "Building Applications" document. In short, you have to note the mapping of standard types between C, C++ and Fortran, and understand the calling conventions of the languages.

Here is a simple example to get you going (I am using Linux, but on OSX things should be similar).

Given cxxmain.cpp, with these lines of code:

[cpp]#include 

extern "C"{
void cstress_(long&, long&);
}

using namespace std;

int main(){
long x=4,y;
cstress_(x,y);
cout << "y = " << y << endl;
}[/cpp]
and fsub.f90, with:
[fortran]subroutine cstress(x,y)
integer :: x,y
y=x*x
return
end subroutine cstress
[/fortran]
I compile them using
[bash]$ ifort -c fsub.f90
$ icpc cxmain.cpp fsub.o
[/bash]
and run the resulting program
[bash]$ ./a.out
y = 16
[/bash]
Note that in Linux icpc/ifort an underscore is appended in C++ to the Fortran subroutine name, and that the default calling convention in Intel Fortran is to call by reference. On Windows, you may use cstress (no underscore) in the C++ main, and compile the Fortran subroutine with the /Qlowercase option.
0 Kudos
Reply