debug error

T

Tiza Naziri

Hi,

Can anybody explain to me why this error occurs (during execution in
MVC++):

Debug Error!

Program: C:\..(my code name)
Module:
File i386\chkesp.c
Line: 42

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.

(Press Retry to debug the application)

Regards,

-- tiZa Naziri --
 
U

Ulrich Eckhardt

Tiza said:
Can anybody explain to me why this error occurs (during execution in
MVC++): [...]
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.

This is a bit outside the scope of plain C, but rather an implementation
detail. There are different ways to call a function. These mainly differ
in how things are stored on the stack and by whom, i.e. last argument
first vs last argument last, caller cleans stack vs callee cleans stack,
things that are passed in registers(ESP is one such register). This is
called the 'calling convention' of a function.

Under win32, different calling conventions are in use, which you can
specify with prefixes to your function declarations or compiler settings.
If you call one function with the compiler believing it was convention X
but implement the function with convention Y, you get above error (if
you're lucky!).
So, double check these:
- when mixing C and C++, make sure all plain C functions are declared
'extern "C"' for the C++ compiler (and only for that compiler make sure
via 'defined(__cplusplus)' and the preprocessor.
- when compiling, make sure the implementation file also includes the
header where the functions are declared, so you can't have any divergences
between the two. This is a good idea anyways.
- with your compiler, you can select the default calling convention which
is used for functions not otherwise marked. Make sure these match between
different compilation units.
- when using function pointers, the calling convention is in fact part of
the type of that function.

In case you have further questions about your particular calling
conventions or your compiler, please first consult the documentation and
then ask in a group dedicated to your compiler. While the general problem
is affecting every implementation of C, its details are still not suitable
for discussion here.

cheers

Uli
 
M

Mark McIntyre

Hi,

Can anybody explain to me why this error occurs (during execution in
MVC++):

You've provided the wrong sort of information. Compile your programme
in debug mode, step through it, and identify where the error arises.
File i386\chkesp.c

Note that this is some system module. The error occurred somewhere
completely different but only showed up here. Its like falling off a
cliff - the error was to step off, but the problem only shows up when
you strike the ground further down...
 
S

Steven K. Mariner

Note that this is some system module. The error occurred
> somewhere completely different but only showed up here. Its
> like falling off a cliff - the error was to step off, but the
> problem only shows up when you strike the ground further
> down...

I like that description. Mind if I gank it for future use?

_________________
Steven K. Mariner
(e-mail address removed)
http://home.earthlink.net/~marinersk/
http://www.whirlyjigmusic.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top