1

I am trying to use dmalloc with g++ 4.7.

The error message i am getting are:

/usr/include/dmalloc.h:457:32: error: declaration of 'char* strdup(const char*)' has a different exception specifier
/usr/include/string.h:130:14: error: from previous declaration 'char* strdup(const char*) throw ()'
  1. Why do C functions throw exceptions?
  2. Can i somehow tell the compiler to ignore the throw() specifier at compile time?

...or do i have to somehow patch dmalloc?

arved
  • 4,401
  • 4
  • 30
  • 53

2 Answers2

1

C functions do not throw exceptions, but exceptions can propagate across C-function frames. The throw() spec tell the compiler that no exception can come out of this function, whether generated by the function or generated by some other function down the chain.

In this case you're compiling a C++ source, which happens to contain an external declaration of a function with C linkage. This alone does not allow the compiler to draw conclusions neither about the library, which contains the function, nor about the language, used to implement that function, thus the compiler cannot assume anything about exceptions and has to compile code conservatively, had the throw() spec not been put there.

You have to update and/or patch dmalloc.

chill
  • 16,470
  • 2
  • 40
  • 44
0

Remove the declaration of strdup from dmalloc.h. It seems to play tricks with the C library that no longer work.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836