This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

behavior of egcs?


Hi!

I'm working with gcc 2.7.3 at the moment and some things don't work as
expected. Now I'm wondering if egcs has the same behavior or if not. 

So it would be nice if someone could test the following simple progs
with egcs.
Please note that I'm running under Linux 2.0.33 using gcc 2.7.3 with
libc 5.4.44, libg++ 27.2.8. My malloc has the function mstats() maybe
yours has some other function to give you some insight to memory usage.

Any hints will be greatly appreciated.


Example 1: 
calling virtual member functions in the constructor doesn't seem to work
(I couldn't find a definition wether the output of my compiler is wrong
or not - I suppose it's wrong):

------------ snip -------------
#include <iostream.h>

class A
{
public:
  A(int i);
  test_method(int j);
protected:
  virtual vmethod(int i);
};

class B: public A
{
public:
  B(int i);
protected:
  vmethod(int i);
};

A::A(int i)
{
  cout << "in A's constructor i=" << i << endl;
  vmethod(i);
}

A::test_method(int j)
{
  cout << "in A's test_method j=" << j << endl;
  vmethod(j);
}

A::vmethod(int i)
{
  cout << "in class A vmethod called with i=" << i << endl;
}

B::B(int i) :
  A(i)
{
  cout << "in B's constructor i=" << i << endl;
}

B::vmethod(int i)
{
  cout << "in class B vmethod called with i=" << i << endl;
}

int main(void)
{
  A test_A(1);
  B test_B(2);

  cout << endl;
  test_A.test_method(3);
  cout << endl;
  test_B.test_method(4);
  cout << endl;

  return 0;
}

-------------------------------

my output:

in A's constructor i=1
in class A vmethod called with i=1
in A's constructor i=2
in class A vmethod called with i=2    <=== **** so what's that ? 
in B's constructor i=2

in A's test_method j=3
in class A vmethod called with i=3

in A's test_method j=4
in class B vmethod called with i=4

-------------------------------

I marked the line in question, I would expect: in class B vmethod called
with i=2 as is shown as the last line of output...


Example 2:
Occuring exceptions while creating objects via new in free store give
memory leaks (section 14.4.4 Stroustrup C++ programming language 3rd ed.
seems to define this as I would have expected).
As an addition the thrown excepetion also causes memory leaks as you can
see when uncommenting out the marked line in class Exception...

------------ snip -----------------

#include <malloc.h>
#include <iostream.h>

class Exception 
{
  // try commenting this out:
  // char tmp[20000];
};

class TestMem
{
public:
  char tmp[2000];
  TestMem();
};

TestMem::TestMem()
{
  throw Exception();
}

int main (void)
{ 
  TestMem *T = 0;

  malloc_stats();
  try
    {
      T = new TestMem[10];
    }
  catch (...)
    {
      cout << "caught an exception...\n";
    }
  malloc_stats();

  return 0;
}

-----------------------

my output:

max system bytes =      29484
system bytes     =      29484
in use bytes     =      17076
max mmap regions =          0
caught an exception...
max system bytes =      49964
system bytes     =      49964
in use bytes     =      37100
max mmap regions =          0

when commenting out in Exception system bytes and in use bytes
increase...



Bye,

Thomas Handler



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