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

Many Fortran code! How to call Fortran code from C/C++? vice versa

losemind
Beginner
330 Views
Many Fortran code! How to call Fortran code from C/C++? As a C/C++ programmer, there are a few reasons to use Fortran: (1) Fortran is very similar to Matlab and easy to port; (2) Fortran has support of complex numbers and vectorized numbers and the operations in Fortran are naturally element-wise, operating on a whole vector. (3) There are many scientific codes are in Fortran. ------------- So how do I call Fortran program from my C program? I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also the Intel Visual Fortran therein. To give an example, I want to call a Fortran program from C++, which is in its bare form, it is a function that evaluates something and pass the results back; I also want to call C++ from Fortran, one example is that many good numerical integral codes are in Fortran, but I want to provide my integrand function in C++. How to do these interfaces? Pointers and readings are appreciated! Thanks for your help!
0 Kudos
2 Replies
TimP
Honored Contributor III
330 Views
There is a lot of material on this subject in the docs folder which comes with ifort, on traditional, CVF compatible, and Fortran 2003 standard interfaces. Metcalf, Reid, Cohen "fortran 95/2003 explained" has a chapter on ISO C binding, as well as significant errata posted on the web. For C++, you must declare all Fortran references with "extern C" in order to use the traditional or f2003 interface.
0 Kudos
Steven_L_Intel1
Employee
330 Views
As mentioned, there is a large chapter in the Intel Fortran documentation on mixed-language programming, and there are some sample C-Fortran programs installed along with the compiler (in version 10).
0 Kudos
Reply