LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2004, 07:53 PM   #1
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Rep: Reputation: 0
C++ Pointer altered on a member funcion call


Somewhere in my code (I cant post it because it is huge) i had this line:

...
resultglass->addref(configcollection);
...

the debugger got me these:
---------------------------------------------
(gdb) r
Starting program: /home/imoya/proyects/c++/fhbot/fhbotscheduler scheduler.config
Inicializando Scheduler...
.Configuration:
configcollection ptrvalue=134579544

Breakpoint 3, TSingleConfigFormatter::deserialize (this=0x80583d0,
stream=0x8058590 "#\n# Seccionde logs\n#\n\n@log\n\nfile=scheduler.log\nlevel=0\n\n#\n# Seccion del schedule\n#\n\n@schedule\n\nfile=events.tbl") at configuration.cpp:282
282 resultglass->addref(configcollection);
(gdb) p configcollection
$14 = (TPersistenceCollection *) 0x8058558
(gdb) s
TSerializationInfo::addref (this=0x80584d8, value=0x8058568) at persistence.cpp:63
63 fvalues.addelement(value);
(gdb)
---------------------------------------------

Notice the difference between the value of configcollection and the value passed in the function call!!!

configcollection=0x8058558

value=0x8058568

of course, it crash!!!
I'd appreciate any comments and suggestions

thanks in advance,
 
Old 04-02-2004, 03:30 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I guess somewhere in the addref() function, the value of configcollection is changed. What happens when you step through the addref() function? Maybe that'll help you find out where it gets changed.
 
Old 04-02-2004, 07:04 PM   #3
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Original Poster
Rep: Reputation: 0
this is the debug trace:

282 resultglass->addref(configcollection); // next line to execute
(gdb) p configcollection //command who prints
$14 = (TPersistenceCollection *) 0x8058558
(gdb) s
TSerializationInfo::addref (this=0x80584d8, value=0x8058568) at

notice the diference between the configcollection value printed by the debuger and the value notified by the debuger in the function call..

...they are diferent!!!... I just make a step in to the funcion!!!

Thanks any way.


Last edited by moyacuba; 04-02-2004 at 07:16 PM.
 
Old 04-02-2004, 07:09 PM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Is that from within the addref() function? It looks like the same trace from the first post. Can you post the code of addref()?
 
Old 04-02-2004, 07:22 PM   #5
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Original Poster
Rep: Reputation: 0
here is:

void TSerializationInfo::addref(ISerializable* value)
{
fvalues.addelement(value);
ftypes.addelement((void*)_SI_REF_TYPE);
};

class TSerializationInfo{
private:
TCollection fvalues, ftypes;
public:
void addint(const int value);
void adddouble(const double value);
void addstring(const char* value);
void addref(ISerializable* value);
int getsize();
void* getvalue(const int atindex = -1);
int gettype(const int atindex);
~TSerializationInfo();
};

class TPersistenceCollection: public TCollection, public ISerializable{
public:
virtual void serialize(TSerializationInfo* glass);
virtual void deserialize(TSerializationInfo* glass);
};

I hope it help...
 
Old 04-02-2004, 07:35 PM   #6
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Original Poster
Rep: Reputation: 0
Now I'm really in troubles!!!... I had compile the code in VS C++ 6.0 and it runs....

Wow it's incredible but I need it running on linux...

:-(
 
Old 04-02-2004, 07:45 PM   #7
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
Change the value to a constant like this.

void TSerializationInfo::addref( const ISerializable* value)
{
fvalues.addelement(value);
ftypes.addelement((void*)_SI_REF_TYPE);
};

class TSerializationInfo{
private:
TCollection fvalues, ftypes;
public:
void addint(const int value);
void adddouble(const double value);
void addstring(const char* value);
void addref( const ISerializable* value);
int getsize();
void* getvalue(const int atindex = -1);
int gettype(const int atindex);
~TSerializationInfo();
};

class TPersistenceCollection: public TCollection, public ISerializable{
public:
virtual void serialize(TSerializationInfo* glass);
virtual void deserialize(TSerializationInfo* glass);
};
};

Where the compiler complains, This will be the problem. Since value shouldn't be changed, anything that changes it will be flagged as an error.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
member to pointer problem with gcc 3.4.3 asmith Programming 1 01-18-2005 08:40 AM
LQ member progress status from member to senior member............. emailssent LQ Suggestions & Feedback 3 10-11-2004 01:31 PM
C++ pointer to downcast member function Wondre Programming 12 02-21-2003 02:56 AM
c++ Pointer to Member Function Wondre Programming 0 02-15-2003 06:12 PM
how to call a c++ member function from _init()? cybercop12us Programming 2 01-16-2003 06:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration