[ltt-dev] [URCU] C++ incompatibility: macro "max" requires 2 arguments, but only 1 given

Vegard Nossum vegard.nossum at gmail.com
Mon Aug 1 09:25:20 EDT 2011


urcu/compiler.h defines min and max as macros, which leads to problems
with standard C++ headers (and other libraries, probably). For
example, the following program does not compile:

#include <valarray>
#include <urcu-qsbr.h>

int main(int argc, char *argv[])
        return 0;

$ g++ -I userspace-rcu-0.6.4 -L userspace-rcu-0.6.4/.libs test.cc -lurcu-qsbr
test.cc:6:34: error: macro "max" requires 2 arguments, but only 1 given
test.cc: In function ‘int main(int, char**)’:
test.cc:6: error: statement cannot resolve address of overloaded function

Remove the urcu-qsbr.h include and it compiles correctly.

I think the best fix is to either define min and max privately (not
export them) or define them using one of the rcu_ or cmm_ prefixes.
For now, my workaround is to always #undef min and #undef max after
including urcu-qsbr.h.


PS: This compiler error is also sensitive to the order of the
includes, the use of other standard headers, and/or the version of the
standard headers. For example, some versions of the GNU implementation
of <algorithm> will #undef min and max.

More information about the lttng-dev mailing list