3.2.2 c++ compile problems

Craig Rodrigues rodrigc@attbi.com
Mon Dec 23 11:56:00 GMT 2002


On Mon, Dec 23, 2002 at 01:00:11PM -0500, Jack Howarth wrote:
> Craig,
>    Thanks. That improved things a bit. Now I get the following 
> errors...
> 
>    throw (std::bad_alloc)' throws different exceptions
> memalloc.h:22: than previous declaration `void* operator new(unsigned int)'
> /usr/include/c++/3.2.1/new:80: declaration of `void* operator new [](unsigned 



I suggest that you purchase a book which discusses Standard C++
in detail, such as Bjarne Stroustrup's C++ Programming Language, 3rd ed.

g++ 3.x conforms quite closely to Standard C++, so understanding
this standard will help you fix these types of problems.

See the attached patch.
-- 
Craig Rodrigues        
http://www.gis.net/~craigr    
rodrigc@attbi.com
-------------- next part --------------
--- sparky/c++/memalloc.h.orig	Mon Dec 23 13:10:42 2002
+++ sparky/c++/memalloc.h	Mon Dec 23 13:11:41 2002
@@ -19,11 +19,16 @@
 
 #include <stddef.h>	// use size_t
 
+#if __GNUC__ >= 3
+#include <new>
+using namespace std;
+#else 
 void *operator new(size_t size);
 void operator delete(void *p);
 
 void *operator new[](size_t size);
 void operator delete[](void *p);
+#endif
 
 // ----------------------------------------------------------------------------
 // The lines below are for tracking all memory allocated with new.
--- sparky/c++/nmrdata.h.orig	Mon Dec 23 13:12:05 2002
+++ sparky/c++/nmrdata.h	Mon Dec 23 13:16:51 2002
@@ -9,7 +9,12 @@
 #include "spoint.h"		// Use SPoint, IPoint, IRegion
 #include "stringc.h"		// Use Stringy
 
+#if __GNUC__ >= 3
+#include <iosfwd>
+using namespace std;
+#else
 class ostream;
+#endif
 
 class Block_File;
 
--- sparky/c++/format.h.orig	Mon Dec 23 13:13:57 2002
+++ sparky/c++/format.h	Mon Dec 23 13:13:15 2002
@@ -4,8 +4,13 @@
 #ifndef FORMAT_HEADER_INCLUDED
 #define FORMAT_HEADER_INCLUDED
 
+#if __GNUC__ >= 3
+#include <iosfwd>
+using namespace std;
+#else
 class istream;
 class ostream;
+#endif
 
 class Condition;
 class Object_Table;
--- sparky/c++/stringc.h.orig	Mon Dec 23 13:14:32 2002
+++ sparky/c++/stringc.h	Mon Dec 23 13:14:54 2002
@@ -8,8 +8,14 @@
 #undef NULL		// Fix bad define in stddef.h gnu distribution.
 #define NULL 0L
 
+#if __GNUC__ >= 3
+#include <iosfwd>
+using namespace std;
+#else
 class istream;
 class ostream;
+#endif
+
 class List;
 
 class Stringy
--- sparky/c++/savefile.h.orig	Mon Dec 23 13:19:28 2002
+++ sparky/c++/savefile.h	Mon Dec 23 13:19:32 2002
@@ -9,7 +9,13 @@
 #include "list.h"		// Use List
 #include "stringc.h"		// Use Stringy
 
+#if __GNUC__ >= 3
+#include <iosfwd>
+using namespace std;
+#else
 class ostream;
+#endif
+
 class Session;
 
 enum SAVEFILE_TYPE {
--- sparky/c++/memalloc.cc.orig	Mon Dec 23 13:20:53 2002
+++ sparky/c++/memalloc.cc	Mon Dec 23 13:24:58 2002
@@ -11,8 +11,10 @@
 #include "table.h"	// use Table
 #include "utility.h"	// use fatal_error()
 
+#if __GNUC__ < 3
 #undef new
 #undef delete
+#endif
 
 // ----------------------------------------------------------------------------
 //
@@ -40,6 +42,9 @@
 // ----------------------------------------------------------------------------
 //
 void *operator new(size_t size)
+#if __GNUC__ >= 3
+   throw(std::bad_alloc)
+#endif
 {
   void *value = allocate(size);
   if (tracking_memory)
@@ -73,6 +78,9 @@
 // ----------------------------------------------------------------------------
 //
 void *operator new[](size_t size)
+#if __GNUC__ >= 3
+   throw(std::bad_alloc)
+#endif
 {
   void *value = allocate(size);
   if (tracking_memory)
@@ -92,6 +100,9 @@
 // ----------------------------------------------------------------------------
 //
 void operator delete(void *p)
+#if __GNUC__ >= 3
+   throw()
+#endif
 {
   if (tracking_memory)
     forget(p);
@@ -101,6 +112,9 @@
 // ----------------------------------------------------------------------------
 //
 void operator delete[](void *p)
+#if __GNUC__ >= 3
+   throw()
+#endif
 {
   if (tracking_memory)
     forget(p);


More information about the Gcc mailing list