OpenTrespasser / JurassicParkTrespasser

A git-based fork of the Jurassic Park: Trespasser source code.
101 stars 25 forks source link

No min/max macros #125

Closed meekee7 closed 4 years ago

meekee7 commented 4 years ago

The macro versions of min/max have two problems:

  1. They are not typesafe. Arguments of completely different types might be compared (like signed/unsigned), leading to unexpected behavior.
  2. If an argument is an expression with side effects like x++, it might be evaluated twice, which may cause unintended behavior.

The Trespasser code already avoids those macros for the most part and undefines them in some strategic places.

The few remaining usages of the min/max macros are removed. The macro definitions from Windows.h are avoided by global definitions of the NOMINMAX macro and not using the minmax.h header. An exemption is made for box2.h from the 3DS Max SDK, it gets a "scoped" definition of the min macro.