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

Yaakov Selkowitz yselkowitz@cygwin.com
Tue Mar 22 17:57:00 GMT 2016


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:
>>
>> https://github.com/cygwinports/gcc/blob/master/0023-glibcxx-use-c99.patch
>> https://github.com/cygwinports/gcc/blob/master/0026-g%2B%2B-gnu-source.patch
>>
>> 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:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51749

I do plan on working on this for newlib, and possibly even glibc, when I 
have a chance.

-- 
Yaakov



More information about the Newlib mailing list