AnsweredAssumed Answered

MQX new keyword using C++

Question asked by Kevin Flynn on Feb 23, 2011
Latest reply on Apr 18, 2012 by Robert Ussery

 

Hi, 
Hopefully some can help I am having trouble with the new keyword using C++ below is some example code I am using MQX 3.6.2 and a Kinetis K60.
When the program reaches the line "Test *T1 = new Test;" it halts and generates an MQX_UNHANDLED_INTERRUPT(0x0041)

 

The same is also true for something as simple  as

int *p_scalar = new int(5);

 

 

Many thanks in advance

 

#define START_TASK 5
extern void Start_task(uint_32);
extern "C" const TASK_TEMPLATE_STRUCT  MQX_template_list[] = 
   /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */
    { START_TASK,   Start_task, 1500,   5,        "hello",  MQX_AUTO_START_TASK, 0,     0 },
    { 0 }
};
class Test
{
public:  
  Test(void);
  ~Test(){};
  
  void Init(void);
 
  int xx;  
};
 
void Start_task(uint_32 initial_data)
{
 printf("Start Task\n"); 
   
   
    Test *T1 = new Test;
    T1->Init();
   
    while(T1->xx)
    {
  _time_delay(200); 
    }
   
  _mqx_exit(0);
}
void Test::Init(void)
{
    printf("Init\n"); 
  xx=1;  
}
Test::Test(void)
{
  printf("Constructor\n");   
  xx=0;
}

 

Outcomes