Topic: [Q] Initialization of global variables (or
Author: Kalyan Kolachala <kal@chromatic.com>
Date: 1995/05/01 Raw View
c>>Sorry if this subject has been beaten to death. I would
appreciate if
>>someone could tell me how exactly the initialization of
"cout" is
>>ensured before its first use...
>>
>>The reason I'm asking this is because on my compilers, "cout"
is an
>>object and not a pointer.
>
>It's typically done with a very ugly trick.
>
>>before this function gets called. This function assigns the
heap objects to
>cin, cout, and cerr. Thus, the need for the xstream_withassign
classes --
>they allow this assignment to take place.
>
The xstream_withassign classes are no longer there in the
standard. However initialization of cin, cout and cerr can
be done using the placement new operator. On the first
invocation the object is constructed and in the later
constructor calls no action is taken.
This technique is elaborated in Plauger's "Draft standard C++
library".
- Kalyan