This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc 2.96, libstdc++ v3 and efence


I stopped crossposting to gcc-help, since this thread has nothing to do
with the compiler.

Alexandre Oliva wrote:
> 
> On Aug 22, 2000, umbpux@tin.it wrote:
> 
> >> On Aug 21, 2000, Maurizio Umberto Puxeddu <umbpux@tin.it> wrote:
> >>
> >> >   int *p = new int;
> >> >   delete [] p;
> >>
> >> This is wrong.  If you allocate with `new', deallocate with `delete',
> >> not `delete[]'.
> 
> > that was obviously just a typo.
> 
> Not that obviously.  You were reporting a crash, and messing up malloc
> data structures is a common source of crashes :-)
> 
> > but the problem is there, have you seen the back trace?
> 
> Yep.  I think the problem has to do with the fact that some dynamic
> initializers of libstdc++ are using new and delete, but you have
> defined them so as to depend on cout having already been initialized,
> but it depends on some the stuff that's using new and delete.  I.e.,
> I'm not sure your example is valid C++.  It would be nice if we could
> run it, though.

you are right. In fact using 'printf' instead of 'cout <<' fixes the
problem.
Is this valid C++? Can I be sure that it will run with any C++ standard
library?
(As I said I trusted my code because I used it for months with earlier
versions of libstdc++ even if it was broken)

#include <iostream>
#include <stdlib.h>

void *
operator new(size_t m)
{
  // C-style output
  printf("new\n");
  return malloc(m);
}

void
operator delete(void *p)
{
  // C-style output
  printf("delete\n");
  free(p);
}

int
main(void)
{
  int *p = new int;
  delete p;

  return 0;
}

Maurizio Umberto Puxeddu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]