Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 587
user1767754 Avatar asked Feb 14 '23 22:02

user1767754


1 Answers

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.

like image 172
juanchopanza Avatar answered Feb 16 '23 10:02

juanchopanza