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

Mathieu Desnoyers compudj at krystal.dyndns.org
Tue Aug 2 13:21:21 EDT 2011


* Vegard Nossum (vegard.nossum at gmail.com) wrote:
> Hi,
> 
> 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[])
> {
>         std::valarray<int>().max();
>         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.

I'll use the caa_ prefix (which stands for Concurrent Architecture
Abstraction):

caa_min, caa_max.

It is fixed in
commit 2f8a5ae7266ad4fb9ba77cfa1b4a7104d0465096

Thanks for reporting this!

Mathieu

> 
> 
> Vegard
> 
> 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.
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list