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

Value of ESP not properly saved

rforehan
Beginner
1,615 Views

Just when I thought I had the interfaces down between my C++ program and a Fortran DLL, I get this message on returning to the C++ program:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Basically here's the setup:

C++ code:

typedef void (*FortranFunction)(assorted float*, int*, float, int and one char* followed by unsigned int for hidden string length parameter)

Fortran code:

subroutine FortranFunction (parameter list ending with the string)
!MS$ ATTRIBUTES DLLEXPORT :: FortranFunction
USE IFPORT
USE ISO_C_BINDING
integer(C_INT), value, intent(IN) :: x
real(C_FLOAT), dimension(x), intent(IN) :: data_block
yada, yada, yada
character*(*), intent(IN) :: string
...
return
end subroutine

Any suggestions on best approach to finding and fixing this problem will be greatly appreciated.

Dick

0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,615 Views
My experience when presented with a "paraphrase" of problem code is that the cause is due to something left out of the paraphrase, be it syntax or command line options. Unless we can see the actual code, and all compiler options used, all we can do is guess.

What I do when tracking such issues is to watch the value of ESP around all calls in the suspect code and see where it is not being properly reset. If you are using STDCALL somewhere, this can definitely cause a stack problem if not done properly. With the C mechanism, the stack should be popped with an add instruction after the call.

The most common cause of this problem is inconsistent C-STDCALL declarations. It could be in a routine called by your Fortran function.
0 Kudos
rforehan
Beginner
1,615 Views

Steve,

Thanks, I watched the return from the disassembly window and saw that the Fortran DLL was clearing the stack unlike a test app I had written to test out fixes. I looked at the external procedures setting in the DLL's properties and found it was CVF. The DLL is legacy code and was built using Digial Visual Fortran. I changed it to C, REFERENCE and the problem went away - now I just have to fix an old C utilities file that was using stdcall.

Thanks for your help on this over the last week or so. Hopefully I won't be bugging you any more.

Dick

0 Kudos
Reply