user1767754
user1767754

Reputation: 25094

Undefining min and max macros

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

Upvotes: 5

Views: 2819

Answers (1)

juanchopanza
juanchopanza

Reputation: 227418

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.

Upvotes: 9

Related Questions