by savuporo » Tue Jun 26, 2007 10:00 am
by savuporo
Tue Jun 26, 2007 10:00 am
limor wrote:the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.
C++ is used in lots of embedded projects with plenty of success, but you have to be careful of the pitfalls.
Im a embedded developer myself, although i mainly work in 32-bit ARM space, and we mostly use C++ with occassional assembly. We usually have more wiggle room than Atmega.
To avoid bloat, avoid certain language features like RTTI, use templates only very carefully ( good guide is to typedef all the template instances and use only the typedefed types ) and thoroughly think through whether you want exceptions or not. Exceptions add roughly 20% code space and thus increase runtime memory footprint, if you can live without them, great. But this makes error checking everywhere more of a pain, and you cant use certain useful libraries.
Use heap sparingly if at all, and if you do, write or use nondefault allocators tuned for small systems ( dlmalloc is a good implementation, very customizeable )
Look at Stroustrup page
here, search for "embedded". especially interesting reading material is the Joint Strike Fighter coding standards document. It contains lots of good guidelines, with reasoning behind the choices. The analysis is there, you can pick your own conclusions.
In short, C++ is suitable for embedded, and depending on skills of programmer, can actually beat C implementations in size requirements, but definitely it can beat them in readability and maintainability.
limor wrote:the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.
C++ is used in lots of embedded projects with plenty of success, but you have to be careful of the pitfalls.
Im a embedded developer myself, although i mainly work in 32-bit ARM space, and we mostly use C++ with occassional assembly. We usually have more wiggle room than Atmega.
To avoid bloat, avoid certain language features like RTTI, use templates only very carefully ( good guide is to typedef all the template instances and use only the typedefed types ) and thoroughly think through whether you want exceptions or not. Exceptions add roughly 20% code space and thus increase runtime memory footprint, if you can live without them, great. But this makes error checking everywhere more of a pain, and you cant use certain useful libraries.
Use heap sparingly if at all, and if you do, write or use nondefault allocators tuned for small systems ( dlmalloc is a good implementation, very customizeable )
Look at Stroustrup page
here, search for "embedded". especially interesting reading material is the Joint Strike Fighter coding standards document. It contains lots of good guidelines, with reasoning behind the choices. The analysis is there, you can pick your own conclusions.
In short, C++ is suitable for embedded, and depending on skills of programmer, can actually beat C implementations in size requirements, but definitely it can beat them in readability and maintainability.