OpenMP vs. <math.h>

Yaakov (Cygwin/X)
Fri Jan 8 18:42:00 GMT 2010

POSIX allows for <math.h> functions to also be defined as macros. 
Currently, only log2 and log2f are so defined.

These macros pose problems with a few projects which define their own 
static/inline/template log2() (off the top of my head, I can think of 2: 
the CRAN rgl module, and OpenCV; both are C++).  Of course, those can be 
fixed with an #undef log2 after the #include's.

However, I just encountered tonight a much larger conflict: OpenMP/C++ 
and <math.h> are incompatible.  STC attached:

$ g++ -D_GLIBCXX_PARALLEL -fopenmp openmp.cxx -lgomp
In file included from 
                   from openmp.cxx:7:
error: expected `)' before ‘/’ token

It gets even worse if you #include <algorithm> as well, and no, it 
doesn't help to #include <cmath>, although moving the math include after 
all other includes does work.

As this would seem to affect all Newlib platforms, I think the most 
plausible solution is to make the log2 macros dependent on !__cplusplus. 
  Patch attached.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: openmp.cxx
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib-log2-cxx.patch
Type: text/x-patch
Size: 1073 bytes
Desc: not available
URL: <>

More information about the Newlib mailing list