--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote: >Is it not advisable to use C++ for embedded AVR >projects due to excess code size, etc.? In any particular project you may be using different subsets of C++ features. If you choose to not use objects, essentially using C++ as a "better C compiler" you'll see no size difference at all as compared to C. If you do use objects but you avoid virtual methods, avoid creating objects dynamically, and avoid situations that invoke copy constructors, the resulting code for non-static member functions will be very similar to code written in C that passes a structure pointer for the data element, i.e. the implicit "this" pointer serves the same purpose as the explicitly passed structure pointer in C. Even if you do use virtual inheritance, the extra code overhead will be limited to accessing the v-tbl of the object to retrieve the address of the member function to be called plus the indirect call to it. Note, too, that the v-tbl for each class is stored in Flash but it is copied to RAM once at startup so you'll have the extra RAM space used for each class. You'll find "C++ code bloat" warnings on AVR Freaks from time to time and the poster is always challenged to provide an example. So far, no one has been able to demonstrate anything other that what I've outlined above. You're aware, I presume, that the Arduino environment is based on C++. The Arduino code is sometimes criticized for being bloated but, as far as I can tell (and except for the issues described above) it has nothing to do with C++ itself. Don Kinzer ZBasic Microcontrollers http://www.zbasic.net
Message
Re: Mixing gcc C & C++
2012-11-27 by Don Kinzer
Attachments
- No local attachments were found for this message.