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.

Can I encapsulate C++ with C when using XDAIS?

http://processors.wiki.ti.com/index.php?title=Overview_of_C%2B%2B_Support_in_TI_Compilers says that "At present, XDAIS algorithms can be invoked from a C++ application, but cannot be developed and supplied via C++.".  However, the TMS320 DSP Algorithm Standard spru352g.pdf section 2.1 on p 16 says only that "All algorithms must follow the runtime conventions imposed by the C programming language".  Hence it seems to me that as long as C++ was only accessed via extern "C" wrapper functions then suitably-wrapped algorithms could be written in C++.  C and C++ have coexisted for as long as there has been C++:  what am I missing here? 

This would mean creating wrapper functions to replace obj.foo(arg) with extern "C" ret_type obj_foo(argtype arg) { obj.foo(arg); } for each obj/foo pair used, but that may be less painful than rewriting existing C++ in C in order to use the Codec framework.

  • Hi Bruce,

    You can implement your algorithm in any language, including assembly, however chosing C++ might prove challenging, as in the end, you may still end up (re-)writing mostly in C, even if you continue to use a C++ tool chain and methodology to develop the algorithm components. In the end, for compliance and usability in a XDAIS based framework, you still need to deliver a library with the packaging conventions, along with table(s) of interface function pointers (also following naming conventions) which contain pointers to the IALG and other standard C callable interface functions (IRES and IVIDDEC, etc.,). Using C++ may prove difficult unless you use classes with static methods and you would still need to allocate and manage instance state, avoid any memory allocation and  ensure correct operation without use of any memory allocation, calls to constructors and destructors, other system calls ...

    To create an algorithm instance (e.g. the object 'obj' references in your post) you would need to bypass any C++ constructors, and instead use functions that implement IALG interface to allocate and initialize the 'instance', and subsequently activate/deactivate/ etc., and call its 'process' functions -- since it is the only interface Codec Engine and some other XDM based frameworks would use to create algorithm instances and route processing calls to the instances.

    The wrapper function approach you sketch above wouldn't work, since you would need a way to pass 'obj' to function 'foo' and have 'obj' constructed by the framework using IALG interface function calls.

    If you already have an existing C++ code base, you should be able to create a C library converting all class functions, say Class C::foo(arg) to C_foo(objHandle, args) form, and supply IALG based contructor functions which you use to allocate object layaouts similar to your C++ class instances manually. Unfortunatelly there is not much getting around this to become XDAIS compliant.

    Murat

     

    .