home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / problems / g__-1_39.c next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  866 b   |  60 lines

  1. /*
  2.  
  3.  
  4. Bug in g++-1.39.1
  5.  
  6. There seems to be a bug in the argument passing for delete 
  7. operators. In the following example there is a class A with 
  8. a new operator allocating memory using "malloc". And a delete 
  9. operator deallocating this memory using "free". But the argument 
  10. of the delete operator is always 0.
  11.  
  12. This error seems to occur only if A or any class member of A
  13. has a destructor.
  14.  
  15. If I compile the program with g++-1.37.1 it runs correctly, 
  16. i.e., delete gets as argument the same pointer returned by malloc
  17. in operator new.
  18.  
  19.  
  20. */
  21.  
  22.  
  23. #include <stream.h>
  24.  
  25.  
  26. struct A {
  27.  
  28.  int x;   
  29.    
  30.     A() { }
  31.    ~A() { }
  32.    
  33.    
  34. void*  operator new(size_t s)
  35. { void* p = malloc(s);
  36.   printf("A::new      p = %d\n\n",p);
  37.   return p;
  38. }
  39.    
  40.    
  41. void  operator delete(void* p)
  42.  
  43.   printf("A::delete p = %d\n",p);
  44.  
  45.  }
  46.   
  47.  
  48. };
  49.  
  50.  
  51.  
  52. main()
  53.   A* ptr = new A;
  54.  
  55.   delete ptr;
  56.  
  57.  }
  58.