c++ - Use of static data inside iostream header -


this question has answer here:

i playing around on godbolt.org, , noticed "extra code" added compiler 'empty main()' iostream header included.

after looking standards figured needed constructs , initializes objects cin, cout, cerr, clog, wcin, wcout, wcerr, , wclog, if have not been constructed/initialized.

n4606: § 27.5.3.1.6

27.5.3.1.6 class ios_base::init [ios::init]   namespace std {    class ios_base::init {       public:          init();          ~init();       private:          static int init_cnt; // exposition    }; } 

but static data standard says counts number of constructor , destructor calls class init, , initialized zero.

2 sake of exposition, maintained data presented here as: (2.1) — static int init_cnt, counts number of constructor , destructor calls class init, initialized zero.

what don't use of static int init_cnt; here ? why need counting how many times constructor/destructor called ?

based on https://github.com/maniacbug/standardcplusplus/blob/master/ios.cpp#l163 think if needed program @ end when calling destructors global variables can destruct cin, cout, cerr, clog, wcin, wcout, wcerr , wclog.

from http://www.csci.csusb.edu/dick/c++std/september/lib-iostreams.html :

~init();

effects: destroys object of class init. function subtracts 1 value stored in init_cnt and, if resulting stored value one, calls cout.flush(), cerr.flush(), clog.flush(), wcout.flush(), wcerr.flush(), wclog.flush().


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -