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.

C++ versus C

Other Parts Discussed in Thread: TMS320F28335

Hello,

For a new project i have to decide if i want to program in c or c++. I have very little experience with these controllers and tools so i want to ask you.

Are there any performance issues if you compare c to c++? I want to optimize to speed because i have a hard real time application.

With regards

Alex

ps I'm using TMS320F28335

  • Hi Alex,

    Different things are to consider before you decide which compiler to use:

    • first and not to underestimate: all ti examples are coded in C, there is some documentation for specific C++ code available but not that much
    • To my experience, you will have a hard job if you want to be as fast in C++ as in C. Function calls for example are unlikely to be faster in C++ unless you inline them and enable the compiler optimizer.
    • If you have to interface interrupts with C++ you need to write wrappers to your C++ environment which is an additional time penalty

    This "penalty" list is certainly not complete. On the other hand I like to code in C++ since it leads me to a better design - this is a very personal opinion - I know there are a lot of gurus out there that know how to write nice an clean C code, however I am not one of those. As soon as I start with debugging a patch and tamper everywhere and loose the overview very fast. This happens less in my C++ projects, but as I said this is my opinion.

    So my recommendation: If you really have to speed up your application go for C.

    If you think the speed penalty is not that important, + you like the OO approach + you are ready to learn something about embedded C++ it is a good alternative.

    I am very curious what others think about this question ...

    BR Andreas

  • Hi Andreas

    I am proficient just in C, though I get the idea of OO programing, especially through old TI style of mathematical modules. But as they switched to macro functions due to speed considerations (see Optimizing Digital Motor Control Libraries document) I assume that C++ approach is equally slow than original OO style in C (calling functions with structure pointers)

    I would really appreciate if TI guys would expand mentioned document with PID module written in C++ with the same benchmarks they did on OO style in C and for macro functions. It would serve as a reference point regarding execution speed as well as an example of C++. It is my opinion that most of the C2000 users com from EE background and are not so well versed in OO languages and methods, and an example would be greatly appreciated

    Regards, Mitja