Re: basic_ios::init: multiple call standard conform?

Tech-Archive recommends: Fix windows errors by optimizing your registry

kanze_at_gabi-soft.fr
Date: 02/14/05


Date: Mon, 14 Feb 2005 12:17:15 CST

P.J. Plauger wrote:
> "helmut zeisel" <zei2003d@liwest.at> wrote in message
> news:1108101599.164388@news.liwest.at...

> > The code below causes a memory leak on Microsoft Visual C++
> > .NET 2003, but works fine with GCC 3.3.3 (cygwin
> > special). If I compile with -DSINGLE_BASIC_IOS_INIT, the
> > memory leak disappears.

> > It seems that trhe problem comes from calling
> > basic_ios::init twice, in particular via std::ios(this) and
> > via std::ostream(this). What does the standard say: is it
> > allowed to call basic_ios::init twice? What compiler is
> > standard conform, what code version is standard conform?

> The purpose of basic_ios::init is to properly initialize the
> object *after* you construct it, *before* you use it, and most
> certainly *before* you destroy it. Since all members of the
> constructed object are perforce uninitialized, there is no way
> to tell whether you've already called basic_ios::init for the
> second time. (Yes, I'm sure that many of us can contrive
> *some* way to tell, but not one with practical utility
> commensurate with its cost.)

> So I think it's a reasonable interpretation of the C++
> Standard that you should not call basic_ios::init twice for
> the same object.

So how do you avoid calling it twice in a bidirectional stream,
which inherits from both istream and ostream? The only
constructor for istream calls ios::init, and the only
constructor for ostream also calls ios::init.

Read literally, in fact, it would seem that the standard
requires basic_iostream to call basic_ios::init twice. Not that
there's really any way a conforming program could tell. (Read
literally, of course, there are a lot of wierd things in §27.)

--
James Kanze                                           GABI Software
Conseils en informatique orientée objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]


Relevant Pages

  • Re: ctor, operator =
    ... > already constructed object and in general case the implementation of the ... > assignment operator will rely on that fact. ... > depends on your class implementation details. ... copy constructor with operator = is valid?" ...
    (comp.lang.cpp)
  • Re: basic_ios::init: multiple call standard conform?
    ... > compiler is standard conform, what code version is standard conform? ... The purpose of basic_ios::init is to properly initialize the object ... Since all members of the constructed object ...
    (microsoft.public.vc.language)
  • Re: constructor and destructor when initializing sized vector
    ... > jjleto wrote: ... >> int main ... > The constructor you are using above has a second defaulted argument ... > ctor - default constructed object for second constructor parameter ...
    (comp.lang.cpp)