Hi, i am using at the moment TIc6452 DSP and code composer v3.3. i want to use C++ code. do you know how better is using C++ code instead of C code? Any suggestions. Thanks, Ramana.
C++ Code
Started by ●November 25, 2008
Reply by ●November 25, 20082008-11-25
gutta wrote:> i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions.If you know how to program in C++ then use C++, otherwise not. There is no performance penalty in using C++ if you know how to avoid unnecessary constructor/destructor calls. bye Andreas -- Andreas H�nnebeck | email: acmh@gmx.de ----- privat ---- | www : http://www.huennebeck-online.de Fax/Anrufbeantworter: 0721/151-284301 GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc
Reply by ●November 25, 20082008-11-25
On Nov 25, 11:41�am, "gutta" <guttaramana...@yahoo.co.in> wrote:> Hi, > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions. > > Thanks, > > Ramana.If you don't know C++, there is no reason advantage to learn it for most typical DSP applications. It sacrifices some performance/code size for some reusability, not really a prime advantage for most DSP applications where code size and speed are king. Just my opinion.
Reply by ●November 25, 20082008-11-25
On 25 Nov, 17:41, "gutta" <guttaramana...@yahoo.co.in> wrote:> Hi, > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions.Generally speaking, C++ lets you as programmer focus on the problem as opposed to the implementation. Templates let you only one function, but re-use it with many types in many situations. The seminal example is the max(a,b) function which returns the maximum of the numbers a and b. With C++ templates this becomes template<typename T> T max(T a, T b) { if (a>b) return a; return b; } These few lines of code essentially cover all necessary cases, as the compiler will fill in type information from the context where the code is called. In C you need to code one version for chars, one for ints (as well as one for each of the unsigned versions), one for floats, one for doubles and so on. Not only do you as programmer have to implement all these functions in C, but each of them will need to have a unique name. So the templates reduce the workload for you as programmer. Also, with templates the compiler is in a far better position to optimize the executable code than it is with non-template code. However, this comes at a price. You don't have the detailed control of the executable as you might need with the DSP. And you really need to know what you are doing or you might inadvertedly introduce overheads and bottlenecks. If you do general programming: C++ is certainly worth learning. However, C++ might not give you the required detailed control over resources on the DSP, particularly if you near the edges of the performance envelope. Rune
Reply by ●November 25, 20082008-11-25
gutta wrote:> Hi, > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions. >If you have to ask, use C. C++ is good for BIG projects, and for code reuse. In the right hands it can be made to do astoundingly good things. In the wrong hands, it will do astoundingly bad things. When I use C++ on a DSP project (and it does have its place), it's when 98% of the functionality is taking up 20% of the processor's effort, and only the remaining 2% is doing "real" work. Then I code that 98% in C++ for the labor savings, and I code the remaining 2% in C or (more likely) assembly. Remember: C gives you a lot of rope. C++ gives you a lot of rope, with a few nooses already tied and waiting for you. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●November 25, 20082008-11-25
"gutta" <guttaramana_79@yahoo.co.in> writes:> Hi, > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions.Hi Ramana, It is not any better in performance terms, which is what I think you're asking. As others are discussing, there are philosophical differences, however. In my view, one of the main reasons for using C++ over C in a small project is the regularity provided by the constructor/destructor paradigm, e.g., it will be easier for you to catch memory leaks and know exactly where to allocate/deallocate (new/delete) memory. But you can always enforce a similar structure in your C code (and I have done just that in a couple of projects). The difference is who's enforcing the rules: you or the compiler. -- % Randy Yates % "Maybe one day I'll feel her cold embrace, %% Fuquay-Varina, NC % and kiss her interface, %%% 919-577-9882 % til then, I'll leave her alone." %%%% <yates@ieee.org> % 'Yours Truly, 2095', *Time*, ELO http://www.digitalsignallabs.com
Reply by ●November 25, 20082008-11-25
gutta wrote:> Hi, > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > C++ code. do you know how better is using C++ code instead of C code? Any > suggestions.In my experience: Under the assumption that you know what you're doing: C++ code compiles just as well as C code with CCS. There is no performance hit just because you use C++. However, C++ features can easily be misused and you may end up with code that bloats a lot and gets slower due to instruction-cache misses. Also the compile-time could skyrock. CCS is not a fast compiler (no big surprise if you understand what the compiler has to do for each loop). If it helps you: I rewrote/ported a template heavy C++ code back to C simply because of the compile time. 10 minutes turnaround time instead of 5 hours does make a diference in the long turn. Nils
Reply by ●November 25, 20082008-11-25
Tim Wescott wrote:> gutta wrote: >> i am using at the moment TIc6452 DSP and code composer v3.3. i want to >> use >> C++ code. do you know how better is using C++ code instead of C code? Any >> suggestions. >> > If you have to ask, use C. > > C++ is good for BIG projects, and for code reuse. In the right hands it > can be made to do astoundingly good things. In the wrong hands, it will > do astoundingly bad things. When I use C++ on a DSP project (and it > does have its place), it's when 98% of the functionality is taking up > 20% of the processor's effort, and only the remaining 2% is doing "real" > work. Then I code that 98% in C++ for the labor savings, and I code the > remaining 2% in C or (more likely) assembly.I generally do the remaining 2% in C++ as well (and 0.05% in assembly). One thing where I found it useful is for DSP stuff with mixed integer types. Things like multiplying a 1.15 signal with a 4.28 coefficient and not getting confused with the fractional bits. But it must be done right to work well. If you just make a class with overloaded operators, your compiler's optimizer will probably explode in your face. Hence, I generally make a set of macros which either maps my operations to plain integer operations, or to a set of classes. The first is for production code, the second for testing: the compiler will warn me if I accidentally add a 1.15 value and a 0.16 value. In addition, classes allow me to group stuff together more easily, but that's probably just a matter of taste.> Remember: C gives you a lot of rope. C++ gives you a lot of rope, with > a few nooses already tied and waiting for you....on easily accessible trees. But I would second your advice: if he has to ask, he'd better stick with C. Stefan
Reply by ●November 25, 20082008-11-25
On Nov 25, 10:49 am, Andreas Huennebeck <a...@gmx.de> wrote:> gutta wrote: > > i am using at the moment TIc6452 DSP and code composer v3.3. i want to use > > C++ code. do you know how better is using C++ code instead of C code? Any > > suggestions. > > If you know how to program in C++ then use C++, otherwise not. There is > no performance penalty in using C++ if you know how to avoid unnecessary > constructor/destructor calls. > > bye > Andreas > -- > Andreas H�nnebeck | email: a...@gmx.de > ----- privat ---- | www :http://www.huennebeck-online.de > Fax/Anrufbeantworter: 0721/151-284301 > GPG-Key:http://www.huennebeck-online.de/public_keys/andreas.asc > PGP-Key:http://www.huennebeck-online.de/public_keys/pgp_andreas.ascUse of C++ can also result in more function call overhead if you use "virtual" functions, due to run-time accesses of the vptr table, which C++ uses to deference polymorphic function calls. Darol Klawetter
Reply by ●November 25, 20082008-11-25
Darol Klawetter <darol.klawetter@l-3com.com> writes:> Use of C++ can also result in more function call overhead if you use > "virtual" functions, due to run-time accesses of the vptr table, which > C++ uses to deference polymorphic function calls. > > Darol KlawetterThat's a red herring -- unless your subroutines perform no computation and access no variables (i.e. only if all of your functions are empty) the marginal cost of a dereference through the vptr table as a fraction of execution time is nearly immeasurable. If you want to sing from the "C++ is too slow" hymnal, at least turn to #344, "C++ Ruins Locality of Reference" --L






