On 14/09/13 01:25, DJ Delorie wrote: > >> For small targets like this, it is common to compile C++ with "-fno-rtti > > True, but even the "static objects must be initialized" code adds some > runtime space/time cost. It's not much, but the smallest MSP430's > don't have much rom/ram to spare. >
Correct me if I'm wrong here, but this only applies when the initialisation involves a constructor function rather than just assignment of a fixed value. In C, initialisers must always be a compile-time constant, and the static objects are handled just like any global objects (but with non-global names) - they go in the "initialised data" section, and are set up before main() starts by a straight copy of the flash data into the ram data. C++ allows initialisers that are not constant - they can be function calls, or object constructors. For global and file-scope objects, these are all run before main() is called. These might add extra code space because the constructor calls can't be fully inlined here, but it should not be much. For function-local statics, there is an overhead - as far as I understand it, the compiler does the equivalent of this translation: void foo(void) { static type local = constructor(); rest_of_foo(); } implemented very roughly as: void foo(void) { static type local; static bool local_is_initialised = false; if (!local_is_initialised) { local = constructor(); local_is_initialised = true; } rest_of_foo(); } If I am correct here, then yes, this means extra code, extra ram, and extra run-time to handle such static initialised objects. However, I don't really see that as a problem. This is an extra feature that C++ gives you, which you do not have to use - it is therefore fine that there is a cost associated with using the feature. It is not like exceptions, that can sometimes have a cost even if you don't use them - that's why the "-fno-exceptions" flag is nice. I wonder if it would be legal for the compiler to translate the above "foo" into: static type foo_local = constructor(); void foo(void) { #define local foo_local rest_of_foo(); } That way, the static construction of "local" would be done before main() using the table of global constructors (coming after the real global constructors, of course), and therefore minimal overhead. The disadvantage is that such static objects would be constructed whether they are needed or not - but on embedded systems, you usually aim to avoid having functions that are never called, so all static objects would need to be constructed sooner or later. mvh., David ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users