C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pointer woes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Ant
Guest





PostPosted: Sun Feb 26, 2006 5:06 pm    Post subject: pointer woes Reply with quote



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
}
Back to top
Bob Hairgrove
Guest





PostPosted: Sun Feb 26, 2006 5:06 pm    Post subject: Re: pointer woes Reply with quote



On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kksmelly (AT) hotmail (DOT) com> wrote:

Quote:
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
NoSpamPlease (AT) Home (DOT) com
Back to top
Bob Hairgrove
Guest





PostPosted: Sun Feb 26, 2006 6:06 pm    Post subject: Re: pointer woes Reply with quote



On Sun, 26 Feb 2006 18:58:57 +0100, "Frank Schmidt" <fs (AT) example (DOT) com>
wrote:

Quote:
//something happens with ptr

//some code

are not that parts wrong :S


Obviously. :)

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Ant
Guest





PostPosted: Sun Feb 26, 2006 6:06 pm    Post subject: Re: pointer woes Reply with quote

"Bob Hairgrove" <invalid (AT) bigfoot (DOT) com> wrote in message
news:eim302tgs69vul40lo2rc5f3um7935erh0 (AT) 4ax (DOT) com...
Quote:
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kksmelly (AT) hotmail (DOT) 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
NoSpamPlease (AT) Home (DOT) 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
Back to top
Bob Hairgrove
Guest





PostPosted: Sun Feb 26, 2006 6:06 pm    Post subject: Re: pointer woes Reply with quote

On Sun, 26 Feb 2006 17:41:56 GMT, "Ant" <AntWillcox (AT) hotmail (DOT) com>
wrote:

Quote:
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
NoSpamPlease (AT) Home (DOT) com
Back to top
Frank Schmidt
Guest





PostPosted: Sun Feb 26, 2006 6:06 pm    Post subject: Re: pointer woes Reply with quote

Quote:
//something happens with ptr

//some code

are not that parts wrong :S
Back to top
Daniel T.
Guest





PostPosted: Sun Feb 26, 2006 9:06 pm    Post subject: Re: pointer woes Reply with quote

In article <uxkMf.59125$Q22.18168 (AT) fe1 (DOT) news.blueyonder.co.uk>,
"Ant" <kksmelly (AT) hotmail (DOT) com> wrote:

Quote:
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.
Back to top
Ant
Guest





PostPosted: Mon Feb 27, 2006 2:06 am    Post subject: Re: pointer woes Reply with quote

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." <postmaster (AT) earthlink (DOT) net> wrote in message
news:postmaster-E14AF0.15571526022006 (AT) news (DOT) east.earthlink.net...
Quote:
In article <uxkMf.59125$Q22.18168 (AT) fe1 (DOT) news.blueyonder.co.uk>,
"Ant" <kksmelly (AT) hotmail (DOT) 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.
Back to top
Frank Schmidt
Guest





PostPosted: Mon Feb 27, 2006 4:06 am    Post subject: Re: pointer woes Reply with quote

"Ant" <AntWillcox (AT) hotmail (DOT) com> schrieb im Newsbeitrag
news:oDsMf.27207$wl.23981 (AT) text (DOT) news.blueyonder.co.uk...
Quote:
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"
Back to top
Daniel T.
Guest





PostPosted: Mon Feb 27, 2006 3:06 pm    Post subject: Re: pointer woes Reply with quote

In article <oDsMf.27207$wl.23981 (AT) text (DOT) news.blueyonder.co.uk>,
"Ant" <AntWillcox (AT) hotmail (DOT) com> wrote:

Quote:
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.
Back to top
Guest






PostPosted: Mon Feb 27, 2006 4:06 pm    Post subject: Re: pointer woes Reply with quote

Ant wrote:
Quote:
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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.