C++ Virtual function with CodeWarrior Development Studio v3.1 doesn't work?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C++ Virtual function with CodeWarrior Development Studio v3.1 doesn't work?

Jump to solution
2,062 Views
SWDesigner
Contributor I
Hi all,  
 
I have a problem using CW dev. studio v3.1 and virtual functions in C++.  When running the code below I will expect the variable i to count from 0 to 4 (I verified this with another C++ compiler). I'm using P&E ICE to debug this.
 
When the constructor of myClass is running the variable i is initialized to 0, and it works fine.
But when the Run() method in myClass is running for the first time one can see that i isn't zero and that is isn't 1 after the first run.
 
I also noticed that the this pointer changes every time the debugger stops at my break point in the Run() method, and it should be the same all four times, right?
Any ides what might be wrong?
 
I'm using a GB60 processor (M68EVB908GB60 evaluation board) and the following dev. studio is installed:
 
Installed Products:
CodeWarrior Development Studio for Motorola HC08 3.1, build 4210.       
CodeWarrior Development Studio for Motorola HC08 3.1 P&E USB 2.0 Service Pack build 050114.
CodeWarrior Development Studio for Freescale HC08 v3.1 Service Pack GB/GT 60A, build 050711
CodeWarrior Development Studio for Freescale HC08 v3.1 Service Pack Programming Algorithms, build 060221
 
Code:
#include <hidef.h> /* for EnableInterrupts macro */#include <MC9S08GB60.h> /* include peripheral declarations */class Runnable{ public:   Runnable();   ~Runnable();   virtual void Run(void) = 0;}; Runnable::Runnable() { } Runnable::~Runnable() { }class myClass : public Runnable{ public: myClass(); ~myClass(); void Run(void); private: unsigned int i;};myClass::myClass() :i(0){}myClass::~myClass(){}void myClass::Run(void){ i = i + 1;}void main(void) { EnableInterrupts; /* enable interrupts */ /* include your code here */ //Disable watchdog _SOPT.Bits.COPE = 0; Runnable *myRun[2]; myRun[0] = new myClass();       myRun[0]->Run();       myRun[0]->Run();       myRun[0]->Run();       myRun[0]->Run();       for(;;) {   //__RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave this function */}
 
Best Regards,
Christian


Message Edited by SW Designer on 2007-05-10 09:46 PM
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,207 Views
CompilerGuru
NXP Employee
NXP Employee
sorry, but I don't know such an option. I would assume to implement it is not too difficult, but as far as I know it is not done. :smileysad:
(Well, I would not think of passing the values on the stack, but the compiler could provide an option which it would always store it to the stack as first thing in the function. And then always use the stack afterwards)

So the best advice is to file a service request. Here's the link (copied from Alban):

How to get Technical Support on Freescale Products ?
Click here to Submit a new Service Request now

View solution in original post

0 Kudos
Reply
3 Replies
1,207 Views
CompilerGuru
NXP Employee
NXP Employee
the bug in this case is the debug information.
So the good news is that the code works correctly. The bad news is that parameters passed in register and never stored on the stack (as the implicit this in myClass::Run) don't display properly :smileysad:.

Daniel
0 Kudos
Reply
1,207 Views
SWDesigner
Contributor I
Hi Daniel,
 
Thanks for you fast reply!
 
There isn't any way to place the parameters on the stack instead? Like a compiler flag?
 
Is this fixed in later versions of the CW dev. studio?
 
Best regards,
Christian


Message Edited by SW Designer on 2007-05-11 07:34 AM
0 Kudos
Reply
1,208 Views
CompilerGuru
NXP Employee
NXP Employee
sorry, but I don't know such an option. I would assume to implement it is not too difficult, but as far as I know it is not done. :smileysad:
(Well, I would not think of passing the values on the stack, but the compiler could provide an option which it would always store it to the stack as first thing in the function. And then always use the stack afterwards)

So the best advice is to file a service request. Here's the link (copied from Alban):

How to get Technical Support on Freescale Products ?
Click here to Submit a new Service Request now
0 Kudos
Reply