This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to make C++ algorithm working well packaged by xDM interfaces written in C on DM3730

Hi all,

Help me please. Recently I need to transplant our algorithm on C64+ DSP platform. Our algo is written in C++, which has a large number of object-oriented classes.

But we all know that TI's xDM package is pure C. So can I make codec directly or must change C++ code into C first? And if the former, how should I do?

If you have any resolution or reference material, tell me please, thanks very much.

Best regards,

Danfeng Lu

  • I don't know anything about the xDM API. I can comment in general C++ programming terms. For the most part, C++ objects can be wrappered with C functions. A typical example:

    /*--------my_c_functions.h------------*/
    #ifndef _MY_C_FUNCTIONS_H_
    #define _MY_C_FUNCTIONS_H_

    #ifdef  __cplusplus
    extern "C" {
    #endif

    void *my_c_open(int x);
    int   my_c_do_something(void *p, int y);
    void  my_c_close(void *p);

    #ifdef  __cplusplus
    }
    #endif

    #endif/*_MY_C_FUNCTIONS_H_*/


    //----------my_c_functions.cpp----------------
    #include "my_c_functions.h"
    #include "my_object.hpp" // For MyObject


    extern "C" {

    void *my_c_open(int x)
    {
      MyObject *pobj;
      pobj = new MyObject(x);
      return((void *)pobj);
    }

    int my_c_do_something(void *p, int y)
    {
      int       status;
      MyObject *pobj = (MyObject *)p;
      status = pobj->DoSomething(y);
      return(status);
    }

    void my_c_close(void *p)
    {
      MyObject *pobj = (MyObject *)p;
      delete pobj;
    }

    }//extern "C"

    In the above example, the caller (xDM?) must save the object pointer somewhere. If you don't need to maintain context (one object only) than use a global variable within my_c_functions.cpp to save the object pointer.

    I vaguely remember the TI C++ compiler does not need the extern "C" qualifiers. Every other C++ compiler will need them.

    Hopefully some xDM experts can suggest a more elegant solution.

     

     

  • Thanks all the same.