- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I noticed that when I'm calling a C++ function from my Fortran code, the parameters lose their values.
The C++ function is declared as follows:
extern "C" void __cdecl
GerkCallback(double &inCurrentTime
double *fortranStateProbabilities,
double *fortranStateProbabilitiesDelta )
{
...
}
The Fortran code uses the function like this (I combined all the relevant code together):
REAL*8 T [REFERENCE]
EXTERNAL F
A = T
CALL F(A, YG, YGP)
As I debug this code, I see that A equals 0 before calling F, but when I get to the C++ function, the corresponding parameter inCurrentTime takes some random value. The other params are mangled as well. Both C++ and Fortran code are compiled with the _cdecl calling convention. Environment: VC++ .Net, Intel Fortran 7.1.
Pavel
I noticed that when I'm calling a C++ function from my Fortran code, the parameters lose their values.
The C++ function is declared as follows:
extern "C" void __cdecl
GerkCallback(double &inCurrentTime
double *fortranStateProbabilities,
double *fortranStateProbabilitiesDelta )
{
...
}
The Fortran code uses the function like this (I combined all the relevant code together):
REAL*8 T [REFERENCE]
EXTERNAL F
A = T
CALL F(A, YG, YGP)
As I debug this code, I see that A equals 0 before calling F, but when I get to the C++ function, the corresponding parameter inCurrentTime takes some random value. The other params are mangled as well. Both C++ and Fortran code are compiled with the _cdecl calling convention. Environment: VC++ .Net, Intel Fortran 7.1.
Pavel
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmmm... too little data to bring a definitive conclusion. For the start, are A, YG, and YGP double precision variables? (I assume they are -- even if they aren't, symptoms would be different).
Try watching LOC(A), LOC(YG) and LOC(YGP) on Fortran side, and addresses of Callback's dummy arguments on C++ side. Are they the same?
Jugoslav
Try watching LOC(A), LOC(YG) and LOC(YGP) on Fortran side, and addresses of Callback's dummy arguments on C++ side. Are they the same?
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found the answer:
The variable A was typed implicitly, and apparently its type was not "REAL*8" (which is the same as double, which was expected by the C++ code). When I explicitly specified the type of A as REAL*8, the problem went away.
The variable A was typed implicitly, and apparently its type was not "REAL*8" (which is the same as double, which was expected by the C++ code). When I explicitly specified the type of A as REAL*8, the problem went away.
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