- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
__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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's true.
And what should I use in mac OS?
And what should I use in mac OS?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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]#includeand fsub.f90, with:
extern "C"{
void cstress_(long&, long&);
}
using namespace std;
int main(){
long x=4,y;
cstress_(x,y);
cout << "y = " << y << endl;
}[/cpp]
[fortran]subroutine cstress(x,y)I compile them using
integer :: x,y
y=x*x
return
end subroutine cstress
[/fortran]
[bash]$ ifort -c fsub.f90and run the resulting program
$ icpc cxmain.cpp fsub.o
[/bash]
[bash]$ ./a.outNote 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.
y = 16
[/bash]

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