I had to make several code modifications to be able to compile cleanly
on VC++ 2005. Here are a few cross-platform (hopefully..) suggestions
for the code base:
(1) in api/nlopt.h, define NLOPT_EXTERN as follows:
#if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__))
# define NLOPT_EXTERN(T) __declspec(dllexport) T NLOPT_STDCALL
#elif (defined(_WIN32) || defined(__WIN32__))
# define NLOPT_EXTERN(T) extern __declspec(dllimport) T NLOPT_STDCALL
#else
# define NLOPT_EXTERN(T) extern T NLOPT_STDCALL
#endif
(2) Suggest defining NLOPT_EXTERN_DAT:
#if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__))
# define NLOPT_EXPORT_DAT(T) __declspec(dllexport) T
#elif (defined(_WIN32) || defined(__WIN32__))
# define NLOPT_EXPORT_DAT(T) __declspec(dllimport) T
#else
# define NLOPT_EXPORT_DAT(T) extern T
#endif
And decorating nlopt_algorithm_name as follows -
NLOPT_EXPORT_DAT(const char *nlopt_algorithm_name(nlopt_algorithm a));
(3) Suggest changing NLOPT_DEPRECATED into a functional macro:
# define NLOPT_DEPRECATED(x) x __attribute__((deprecated))
#elif defined(_MSC_VER)
# define NLOPT_DEPRECATED(x) __declspec(deprecated) x
#else
# define NLOPT_DEPRECATED(x) x
#endif
And then wrapping every NLOPT_DEPRECATED function with this macro.
(4) in api/nlopt.hpp, suggest modifying mythrow so that it wouldn't
throw every exception *after* a matching case:
void mythrow(nlopt_result ret) const
{
switch (ret)
{
case NLOPT_FAILURE:
{
throw std::runtime_error("nlopt
failure");
break;
}
case NLOPT_OUT_OF_MEMORY:
{
throw std::bad_alloc();
break;
}
case NLOPT_INVALID_ARGS:
{
throw std::invalid_argument("nlopt
invalid argument");
break;
}
case NLOPT_ROUNDOFF_LIMITED:
{
throw roundoff_limited();
break;
}
case NLOPT_FORCED_STOP:
{
throw forced_stop();
break;
}
default: break;
}
}
(5) in optimize.c, suggest modifying the POP macro to use
stochastic_population accessors:
#define POP(defaultpop) (opt->stochastic_population > 0 ?
\
opt->stochastic_population :
\
(nlopt_get_stochastic_population() > 0 ?
\
nlopt_get_stochastic_population() :
(defaultpop)))
(6) in DIrect.c, there seems to be some wrong error reporting. Suggest
changing lines 535-540 to -
if (oops) {
if (logfile)
fprintf(logfile, "WARNING: max eval reached in
routine DIRsamplepoints \n");
*ierror = 2; //-4;
goto cleanup;
}
(7) Both luksan\pssubs.c and neldermead\sbplx.c make use of
'copysign()'. In the MS CRT this functionality is exposed as
'_copysign()'. Suggest wrapping this function in a platform-sensitive
macro, say somewhere in nlopt-internal.h
(8) Suggest defining min(a,b) , max(a,b) and iabs(x) in a central
location (say nlopt-internal.h) rather than repeating it in ~15
different locations.
I did various other hacks and modifications intended to avoid compiler
warnings (explicit casts and such), but the above suggestions are
hopefully 'clean' enough to be suggested as fixes.
Best,
-Ofek Shilon
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss