- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
I have a Fortran static Library with one subroutine. I call that subroutine from C++ and I pass one array, inside the subroutine the array change its values but when I use it again in C++ I just get a single value.
Here it's the code
C++
#include "stdafx.h" #include "iostream" using namespace std; extern "C"{ void LIBRERIA(int *ENTERO, double *DOBLE, double *ARREGLO); } int _tmain(int argc, _TCHAR* argv[]) { int ent = 5; double dou = 2; double arre[5]; LIBRERIA(&ent, &dou, arre); cout << *arre << endl; }
Fortran subroutine
Subroutine Libreria(entero, doble, arreglo) implicit none integer entero double precision doble, numerito double precision, dimension(entero) :: arreglo print*, "Inside the library" numerito = entero * doble arreglo(:) = numerito print*, arreglo End subroutine
Thanks for any help.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your C++ code is only writing a single value to the console. If you want to write all the elements of `arre`, then you need a loop or similar.
#include "stdafx.h"
#include <iostream>
using namespace std;
extern "C"{
void LIBRERIA(int *ENTERO, double *DOBLE, double *ARREGLO);
}
int _tmain(int argc, _TCHAR* argv[])
{
int ent = 5;
double dou = 2;
double arre[5];
LIBRERIA(&ent, &dou, arre);
for (int i = 0; i < ent; ++ i) cout << arre << endl;
}
For robustness, you should consider using Fortran 2003's C interoperability features in your Fortran code.
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