What does NOMINMAX do?
When compiling in Microsoft Visual C++ you may come across the preprocessor directive NOMINMAX. This undefines the macros MIN and MAX which are specified in the windows headers. In Visual C++ v 6.0 this may be in C:\Program Files\Microsoft Visual Studio\VC98\Include\windef.h where we have
#ifndef NOMINMAX
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif #ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#endif /* NOMINMAX */
Using macros to do this is a bad idea, as discussed here. The standard library has templated functions std::min and std::max which are much better. Defining NOMINMAX before any #includes of windows.h prevents the macros from being defined and allows the use of the templated functions defined in algorithm.
Posted in Software |