Advice needed - gcc and exceptions

Jim White mathimagics at
Wed Apr 26 02:27:25 CEST 2006

Is there an exception handling capability in gcc "C"
(not C++) ???

I'm trying to implement a "Bounded Knapsack Problem"
solver, with a view to adapting it for GMP.  The
algorithm is from a reliable source, David Pisinger,
who has much published work in this area.

He provides C code for many of his algorithms, at

The one I am working with is "bouknap.c".

This is conveniently provided as a library function,
so I was easily able to get the base version working
with gcc (I'm on Windoze XP, using MinGW).  Before I
begin introducing a GMP strategy, I wanted first to
verify it against some known results I already had
obtained using brute force.

These verification tests require 64-bit integers (only
for the weights and the constraint values, the number
of variables and maximum range of coefficients is in
fact quite small)

David's code is intelligently organized, so that
macros are used for typedefs of the different array

So I used "long long" for the weight array, and it all
works fine, and works perfectly for some of my test
cases, but crashes on others.  

The algorithm is complicated and very recursive, etc,
and I need to be able to trap that exception and find
out just where it's happening.  (Unfortunately I've
been unable to contact David Pisinger so far)

How should I go about this?  Does 'C' have
exception-trapping capability?  Does MinGW gcc-C ? Or
do I have to compile it with C++, of which I know
diddly-squat. Is regular C a true subset?


Jim White
ANU, Canberra

More information about the gmp-discuss mailing list