Roman Shchugarev wrote:
> Hi 
> 
> Got myself in to trouble once again, it is said in libq header that to use 
> libpqxx I 
> need to define NOMINMAX option, but in that case I am unable to use #include <
> afxtempl.h> (Using MS VisualStudio .NET2k3). What are the consequences of not 
> using NOMINMAX definition and just commenting out the error 
> #error "Oops: min() and/or max() are defined as preprocessor macros.\
>   Define NOMINMAX macro before including any system headers!"
> ?????

The problem is that windows.h defines max and min as macros while the 
C++ standard library defines std::max and std::min as function 
templates. The defines in windows.h give libpqxx trouble invoking 
std::max and std::min later on. This may lead to problems because, among 
other things:

(a) std::max(a,b) will expand into std::BLAHMACROGARBLEETC, which isn't 
syntax compilers are likely to like.

(b) Even if libpqxx invokes max and min without explicitly specifying 
the std:: namespace, then the macros will be called instead of the std:: 
versions, and the macros may cause side effects of their arguments to 
occur multiple times for one invocation, like this:

int a = 2, b = 1;
max(a++,b);
std::cout << a; // may print more than 3.

may cause

(c) It's untested. :-)


I can suggest two possible solutions:

1. Include afxtempl.h and all other system headers that require FIRST, then:

#undef min
#undef max

and only then include libpqxx.

2. Include *all* that you need of libpqxx before including *any* Windows 
or MFC headers. Then NOMINMAX is not needed, as libpqxx will not be 
included with min and max defined.

Cheers,
Bart
_______________________________________________
Libpqxx-general mailing list
Libpqxx-general@gborg.postgresql.org
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to