ISO C99 support in <math.h> for C++98

Yaakov Selkowitz
Tue Mar 22 18:54:00 GMT 2016

On 2016-03-22 13:18, Andre Vieira (lists) wrote:
> On 22/03/16 17:56, Yaakov Selkowitz wrote:
>> On 2016-03-22 12:46, Andre Vieira (lists) wrote:
>>> On 22/03/16 15:42, Yaakov Selkowitz wrote:
>>>> We also had issues enabling C99-in-C++ on Cygwin (which is based on
>>>> newlib), which required a few patches:
>>>> It is on my to-do list to get this working on newlib targets once we
>>>> have a snapshot with the new feature test macros.
>>> Ok so I now know where the problem is coming from, its the fact that
>>> _GLIBCXX98_USE_C99_MATH is defined based on the configure which uses
>>> -std=g++98, whereas the test in libstdc++ uses -std=gnu++98. The first
>>> ends up with a __ISO_C_VISIBLE 1990 the latter 1999 because
>>> _POSIX_C_SOURCE is defined as 200809L for gnu++98 and undefined for
>>> c++98.
>>> This was working before because the C99 functions would always be
>>> included when compiling for c++ due to the || defined(__cplusplus),
>>> adding this back would fix it, but I'm assuming you removed it for a
>>> reason. I will look further into why this discrepancy in macros for
>>> c++98 and gnu++98.
>> AFAICS the configure tests are incorrect here.  C++98, which obviously
>> predates C99, can not and should not rely upon nor expose the latter's
>> features.  The feature test macros *do* enable C99 and C11 when C++11 or
>> newer is in effect.
>> Note that this is part of a larger issue, which affects glibc as well:
>> I do plan on working on this for newlib, and possibly even glibc, when I
>> have a chance.
> OK, so the configure test is working as intended and the same test when
> compiled with -std=c++98 behaves fine too.
> The problem comes from the fact that this test uses -std=gnu++98 and
> gnu++98 reuses the same macro, _GLIBCXX98_USE_C99_MATH, set by that
> configuration step. However, as I mentioned the ISO_C_VISIBLE values are
> different for these two. I now figured out this is because c++98 sets
> __STRICT_ANSI whereas gnu++98 does not. This together with the absence
> of __XOPEN_SOURCE leads to 'newlib/libc/include/sys/features.h' defining
> POSIX_C_SOURCE as 200809L and eventually the different ISO_C_VARIABLE.

There's nothing wrong with -std=gnu++98.  The problem is with configure 
testing C99 macros with -std=c++98, which makes no sense and only works 
on glibc because they use -D_GNU_SOURCE indiscriminately with g++.  Fix 
those configure tests to use -std=c++11, as we did on Cygwin, and the 
features should be enabled.


More information about the Newlib mailing list