i have in my legacy code this
#define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y)
that bean used allot in the application , now i try to compile it in freeBSD
and i keep getting :
/usr/include/c++/4.2/bits/istream.tcc:123:35: error: macro "min" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:124:45: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:143:33: error: macro "min" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:144:43: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:438:48: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:441:53: error: macro "min" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:449:47: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:489:48: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:493:53: error: macro "min" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:501:47: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:507:53: error: macro "max" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:806:43: error: macro "max" requires 2 arguments, but only 1 given
i guess its the name of the methods in the code ( the macros ) .
now changing the name its to much work.
how can i keep using it but avoiding the compiler to mixup ?
What was the reason to define those macros in the first place? It’s C++, no need for any macros, especially not those that are already given as functions to you by the standard (It always bothers me when including
<windows.h>and getting complaints about their stupidminandmaxmacros).That being said, a quick and dirty solution might be to substitute your macro definitions with
Though, this still pollutes the global namespace those are now proper function names that can be hidden by any local variables or any other functions or methods and are not just replaced everywhere by a stupid text-substituting preprocessor.
Other than that consider including any system include files before those macros (or
usings).