AnsweredAssumed Answered

Compiler question: doesn't call global instance constructor

Question asked by Haihang Sun on Nov 24, 2009
Latest reply on Mar 8, 2013 by sam s

Hi,

 

I am using  Codewarrior development studi for ColdFire V7.1

 

The test code I have like below:

 

-------------------------------------------------------------

class testGroupStackTest
{ public:
    

     testGroupStackTest ()     {    dummy =123;   }
   
     int getdummy()    {    return dummy;  }
   
     int dummy;
 };

testGroupStackTest testGroupStackInstance;

/* Task IDs */
#define HELLO_TASK 5

extern void hello_task(uint_32);

extern "C" const TASK_TEMPLATE_STRUCT  MQX_template_list[] =
{
   /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */
    { HELLO_TASK,   hello_task, 1500,   5,        "hello",  MQX_AUTO_START_TASK, 0,     0 },
    { 0 }
};


void hello_task
   (
      uint_32 initial_data
   )
{
int i;
//testGroupStackTest testGroupStackInstance;

   printf("\n Hello World \n");
 
   i=testGroupStackInstance.getdummy();
   printf("dummy=%d\n",i);

   printf("\n Tests Done \n");

  _mqx_exit(0);

}
------------------------------------------------------

 

if I define testGroupStackInstance as Global instance, the constructor is never got called, the i value I get is Zero. however if I define testGroupStackInstance inside the task, I can get the correct i value dummy =123. What I am missing here?

 

Your help is great appreciated.

 

Thanks.

 

J.

Outcomes