Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Stack address not properly saved across function call.

Intel_C_Intel
Employee
620 Views
I have C++ code that calls a few Fortran routines. (Legacy software that can not be rewritten into C++.) I am getting the following runtime error:

The value of ESP was not properly saved across a function call. ...

I am assuming that this is coming from one of my Fortran subroutine calls. I get the message when I return from the subroutine. I see nothing wrong with the declarations and definitions. I've gotten other Fortran subroutines to function with no warnings or errors. The code functions correctly when I stepped into it and examined variable values.

The C declaration is:
extern "C"
{
void XFERCONS_C_SCISIM( double J1[],
double C1[],
double C2[],
double L1[],
double M2[],
double U1[],
double U2[] );
}

The C call is:
void TCII_SCISIM_Interface::CALL_XFERCONS(
double J1[],
double C1[],
double C2[],
double L1[],
double M2[],
double U1[],
double U2[] )
{
// note that arguments are addresses of parameters
XFERCONS_C_SCISIM( J1, C1, C2, L1, M2, U1, U2 );
}

The Fortran subroutine is:
SUBROUTINE XFERCONS_C_SCISIM ( J1,
. C1,
. C2,
. L1,
. M2,
. U1,
. U2)
REAL*8 J1(MAX_NUM_CONSTANTS)
REAL*8 C1(MAX_NUM_CONSTANTS)
REAL*8 C2(MAX_NUM_CONSTANTS)
REAL*8 L1(MAX_NUM_CONSTANTS)
REAL*8 M2(MAX_NUM_CONSTANTS)
REAL*8 U1(MAX_NUM_CONSTANTS)
REAL*8 U2(MAX_NUM_CONSTANTS)

INTEGER*4 I

DO I = 1,MAX_NUM_CONSTANTS
J1CON(I) = J1(I)
C1CON(I) = C1(I)
C2CON(I) = C2(I)
L1CON(I) = L1(I)
M2CON(I) = M2(I)
U1CON(I) = U1(I)
U2CON(I) = U2(I)
ENDDO

END

Any help with solving this issue will be greatly appreciated.

Thanks,
George
0 Kudos
1 Reply
Steven_L_Intel1
Employee
620 Views
Add __stdcall after the "C" in your C (actually C++) declaration.

Steve
0 Kudos
Reply