Figure 1: Outline of initialization and cleanup topics and issues in which they were discussed
Topic Issue Appeared In ---------------------------------------------------------------- All Variables March 1999 What should I initialize it to How should I initialize it When should I initialize it Variables that require scarce resources How should I dispose of its resources When should I dispose of its resources Lifetime and initialization Global static variables are initialized once, at program startup Local static variables are initialized once, when the block in which they are defined is first entered Auto variables are initialized every time the block in which they are defined is entered Cleaning up in C atexit ---------------------------------------------------------------- Cleaning up in C++: destructors April 1999 Destructors for static objects, both global and local, are run at program termination, in reverse order of construction Destructors for auto objects are run when the block in which they are defined is exited by any means, including throwing an exception ---------------------------------------------------------------- When the language doesn't do what you need May 1999 Use default 0 initialization to flag variables that haven't been initialized Use a function that returns a reference to a local static object Use the nifty counter trick