473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

pointer woes

Ant
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:
#include "rootclass.h"

int _tmain(int argc, _TCHAR* argv[])
{
CRootClass *testclass;
testclass = new CRootClass;
testclass->TestFunction();

delete testclass;
return 0;
}
class CStore
{
public:
CStore(void);
~CStore(void);
friend class CRootClass;
typedef void(CRootClass::*FunctionPtr)(void);
void PassPtr(FunctionPtr FPtr);
};

#include ".\store.h"

CStore::CStore(void)
{
}

CStore::~CStore(void)
{
}

void CStore::PassPtr(FunctionPtr FPtr)
{
//something happens with ptr
}

#include ".\store.h"
class CRootClass
{
public:
CRootClass(void);
~CRootClass(void);

CStore *m_Store;
void TestFunction(void);
};
#include ".\rootclass.h"

CRootClass::CRootClass(void)
{
m_Store = new CStore();
m_Store->PassPtr(&CRootClass::TestFunction );
}
CRootClass::~CRootClass(void)
{
delete m_Store;
}
void CRootClass::TestFunction(void)
{
//some code
}
Feb 26 '06 #1
10 5595
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotmail.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:


[snip]

Your code compiles and runs fine, although it doesn't do anything. You
need to show us the code that produces the error.

(BTW, please refrain from posting code which uses non-standard macros
and extensions such as _tmain and TCHAR).

--
Bob Hairgrove
No**********@Home.com
Feb 26 '06 #2
Ant

"Bob Hairgrove" <in*****@bigfoot.com> wrote in message
news:ei********************************@4ax.com...
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotmail.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across
a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?

Code Follows:


[snip]

Your code compiles and runs fine, although it doesn't do anything. You
need to show us the code that produces the error.

(BTW, please refrain from posting code which uses non-standard macros
and extensions such as _tmain and TCHAR).

--
Bob Hairgrove
No**********@Home.com


Sorry about the TCHAR business, didnt notice that .

Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.

Using Visual Studio 2003 it produces this error

"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.

The program '[3768] friendtest.exe: Native' has exited with code -2147483645
(0x80000003)." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same
Feb 26 '06 #3
On Sun, 26 Feb 2006 17:41:56 GMT, "Ant" <An********@hotmail.com>
wrote:
Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.

Using Visual Studio 2003 it produces this error

"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.

The program '[3768] friendtest.exe: Native' has exited with code -2147483645
(0x80000003)." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same


Here is the code I compiled and ran (all in one file instead of
different headers). It is essentially equivalent to the code you
posted. However, I did remove the "(void)" bits since that just isn't
C++, as well as changed _tmain to main:

// test_store.cpp
class CStore
{
public:
CStore();
~CStore();
friend class CRootClass;
typedef void(CRootClass::*FunctionPtr)();
void PassPtr(FunctionPtr FPtr);
};

CStore::CStore()
{
}

CStore::~CStore()
{
}

void CStore::PassPtr(FunctionPtr FPtr)
{
//something happens with ptr
}
class CRootClass
{
public:
CRootClass();
~CRootClass();

CStore *m_Store;
void TestFunction();
};
CRootClass::CRootClass()
{
m_Store = new CStore();
m_Store->PassPtr(&CRootClass::TestFunction );
}

CRootClass::~CRootClass()
{
delete m_Store;
}

void CRootClass::TestFunction()
{
//some code
}

int main()
{
CRootClass *testclass;
testclass = new CRootClass;
testclass->TestFunction();

delete testclass;
return 0;
}

--
Bob Hairgrove
No**********@Home.com
Feb 26 '06 #4
> //something happens with ptr
//some code


are not that parts wrong :S
Feb 26 '06 #5
On Sun, 26 Feb 2006 18:58:57 +0100, "Frank Schmidt" <fs@example.com>
wrote:
//something happens with ptr

//some code


are not that parts wrong :S


Obviously. :)

--
Bob Hairgrove
No**********@Home.com
Feb 26 '06 #6
In article <ux*******************@fe1.news.blueyonder.co.uk >,
"Ant" <kk******@hotmail.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?


The code you posted is fine, your problem lies elsewhere. Somewhere in
your program you are writing to invalid memory or writing past the end
of an array, this is destroying the runtime environment in unpredictable
ways.

You need to find out where the error really is. Good luck.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 26 '06 #7
Ant
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
In article <ux*******************@fe1.news.blueyonder.co.uk >,
"Ant" <kk******@hotmail.com> wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me
the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved
across a
function call.

It only seems to give me problems if I use the friend class declaration

Any thoughs ?


The code you posted is fine, your problem lies elsewhere. Somewhere in
your program you are writing to invalid memory or writing past the end
of an array, this is destroying the runtime environment in unpredictable
ways.

You need to find out where the error really is. Good luck.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.

Feb 27 '06 #8

"Ant" <An********@hotmail.com> schrieb im Newsbeitrag
news:oD******************@text.news.blueyonder.co. uk...
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip


With all the single files, a #include "rootclass.h" in store.cpp and some
#pragma once in the headers seems to solve the problem. At least on vs2005.

I'm tiered to find the explanation somewhere in "type not known enought for
a stupid compiler"
Feb 27 '06 #9
In article <oD******************@text.news.blueyonder.co.uk >,
"Ant" <An********@hotmail.com> wrote:
thanks for the replies.

I can appriciate that it that it would appear the error lies elsewhere, I
thought so too. The code posted is the entire code , the commens are not
snips to make it easier to post, its the entire program. I suspect its
something to do with a Microsoft compiler flag I need to set/unset

To demonstrate that this is the code that fails and it does not lie
elsewhere in some unsibmited code I can like you to my source files. Sorry
but they are in MS format, its the only compiler I have

http://www.teamkk.com/temp/friendtest.zip


The code above gives me an idea. Where do you make these CRootClass
objects? If you try to make one *inside* CStore, that would be a real
problem.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 27 '06 #10

Ant wrote:
Hi,

I am having trouble with a member function pointer. It sees to give me the
followign error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.


As your code is incomplete, I'm going to guess based on symptoms. I
guess
you're improperly mixing member function pointers and normal function
pointer.
This probably takes the form of a C cast, or a reinterpret_cast.

NB. Pointers to static member functions have the same type as to free
functions.

Regards,
Michiel Salters

Feb 27 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have...
0
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade...
3
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can...
2
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have...
0
by: Arun Bhalla | last post by:
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1. ...
15
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here...
48
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
9
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789...
1
by: hdogg | last post by:
Scope Woes - IF statement nested in WHILE statement -PHP I have an array $actuals_sum. <?php while(conditions) { if($i == '24) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.