5

In a source code, I saw that min and max were being undefined. What could be the reason for that?

// remove stupid MSVC min/max macro definitions
#ifdef WIN32
   #undef min
   #undef max
#endif
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
user1767754
  • 23,311
  • 18
  • 141
  • 164

1 Answers1

8

Some MSVC header has pre-processor macros to define min and max. This is bad for many reasons. First, they are not reserved names, second, there are standard library functions with the same names.

So MSVC or whatever was breaking the rules and code by defining min and max as macros, and the use of undef is a work-around to fix that problem.

See this related question, which shows how the defines can break code.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480