Hi Florian, I would suggest to let the exception propagate, otherwise the code will run without informing the caller about the fact that no constraints will be used.
As a general C++ hint: if you don't want to propagate the exception you should "return 0" right away instead of throwing an exception and then catching it in the same function. "catch" is a very expensive operation that compilers usually do not optimize because it is supposed to not happen very often, and throw/catch breaks the flow of the program making it more difficult to read the code. best regards, Gert On Wed, 2013-06-26 at 16:47 +0200, Florian Dommert wrote: > > -----Ursprüngliche Nachricht----- > > Von: [email protected] [mailto:nlopt-discuss- > > [email protected]] Im Auftrag von Florian Dommert > > Gesendet: Montag, 24. Juni 2013 19:29 > > An: 'Steven G. Johnson' > > Cc: [email protected] > > Betreff: Re: [NLopt-discuss] unsigned vs size_t in add_constraints > > > > > -----Ursprüngliche Nachricht----- > > > Von: Steven G. Johnson [mailto:[email protected]] > > > Gesendet: Montag, 24. Juni 2013 19:17 > > > An: Florian Dommert > > > Cc: [email protected] > > > Betreff: Re: [NLopt-discuss] unsigned vs size_t in add_constraints > > > > > > > > > On Jun 24, 2013, at 1:13 PM, "Florian Dommert" <[email protected] > > > stuttgart.de> wrote: > > > > Hi, > > > > this is surely true, but warnings are annoying in a nice clean code. > > > > Are you interested in a patch? Perhaps I can work one out without > > > > affecting the general behavior. > > > > > > > > > Sure. The simplest option would be to insert a few typecasts into > > nlopt.hpp. > > > Another option would be to change the C interface to use size_t, but > > > I'm reluctant to change the ABI without a stronger motivation. > > > > Fine. In my own opinion, the first option is really the simplest. I will > give it a try > > and send you a patch. > > > > Hello, > > attached is a patch for nlopt.hpp. A public member function convertSize_t > is introduced that casts the size into an unsigned and checks, if the > conversion is correct. Otherwise an exception is thrown. > > However, this is just a first step and only avoids compiler warnings when > linking to nlopt. There are some similar constructs in the nlopt code where > a size_t is used as an unsigned. These warnings are thrown during the > compilation process of nlopt. If I have more time left and you consider the > attached fix as appropriate, then I can also include it at the other > sections of the code. > > Cheers, > Flo > > > > > Cheers, > > Flo > > > > > > _______________________________________________ > > NLopt-discuss mailing list > > [email protected] > > http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss > _______________________________________________ > NLopt-discuss mailing list > [email protected] > http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
signature.asc
Description: This is a digitally signed message part
_______________________________________________ NLopt-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
