adplug / adplay-unix

AdPlug's UNIX console-based frontend
GNU General Public License v2.0
12 stars 15 forks source link

Rename min/max macros to uppercase to fix conflict with `std` namespace #18

Closed dbedrenko closed 2 years ago

dbedrenko commented 2 years ago

Defining min/max in lowercase and then #including stdlib--that already implements std::min and std::max--causes many compilation errors, a sample of which I quote below:

make[1]: Entering directory '/home/danb/abs/adplay/src/adplay-1.8.1/src'
make  all-am
make[2]: Entering directory '/home/danb/abs/adplay/src/adplay-1.8.1/src'
g++ -DHAVE_CONFIG_H -I.  -I/usr/include/libbinio   -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DADPLUG_DATA_DIR=\"/usr/local/com/adplug\"   -g -O2 -MT esound.o -MD -MP -MF .deps/esound.Tpo -c -o esound.o esound.cc
In file included from /usr/include/c++/12.2.0/string:50,
                 from /usr/include/adplug/player.h:25,
                 from output.h:23,
                 from esound.h:23,
                 from esound.cc:25:
/usr/include/c++/12.2.0/bits/stl_algobase.h:278:56: error: macro "min" passed 3 arguments, but takes just 2
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |                                                        ^
In file included from esound.cc:24:
defines.h:38: note: macro "min" defined here
   38 | #  define min(a,b) (((a) < (b)) ? (a) : (b))
      |
/usr/include/c++/12.2.0/bits/stl_algobase.h:300:56: error: macro "max" passed 3 arguments, but takes just 2
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |                                                        ^
defines.h:41: note: macro "max" defined here
   41 | #  define max(a,b) (((a) > (b)) ? (a) : (b))

This didn't use to be a problem because apparently std::min and max were added only in 2011, but this code was written prior to that.

Malvineous commented 2 years ago

Thanks for the fix!