AIX I/O failures

Mark Mitchell mark@codesourcery.com
Thu Jan 25 14:14:00 GMT 2001


>>>>> "Gabriel" == Gabriel Dos Reis <gdr@codesourcery.com> writes:

    Gabriel> I really don't like that hack -- it reminds me the libio
    Gabriel> hack 8-).

It's really completely different.  

The problem with that hack is that it made things unmaintainable:
there was an intimate interdependence between code in the C library
and code in the C++ standard library that depended on details of
object layout.  This made things incredibly fragile, since any change
to the C++ compiler's object model (which changed frequently, and we
all knew it), to the C library (which changed infrequently), or to the
C++ standard library (which needed to change since it wasn't
conformant) was likely to cause problems.  Furthrmore, the people who
maintained those pieces of code were largely separate, so there was
additional fragility.

In this case, all we're doing is allocating some storage, and then
initializing it later. 

It's really no different from saying

  istream* is = malloc (sizeof (istream));
  new (is) istream;

exception that you save the indirection on every use.

A very similar example to the code I wrote occurs as an example in the
standard itself:
 
  char place[sizeof(Something)];
  Something* p = new (place) Something();

The only difference is that there's not the subsequent ODR violations
that emerges in my code.

There's almost no fragility here at all.  If anything changes about
the layout of an istream, or the compiler gets a whole new object
model, everything will continue to Just Work.  It will work with all
the C++ compilers I know about.  There's only one group of people
involved: the libstdc++ maintainers.  As long as they know about the
issue, there are no dependencies with respect to anybody else.

The only problem that could occur would be if the compiler actually
checked for ODR violations.

Still, I'm all for a better way.

My two cents,

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


More information about the Libstdc++ mailing list