public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: Feature Conditional for M_PI
Date: Mon, 31 Aug 2020 17:27:15 +0200	[thread overview]
Message-ID: <20200831152715.GC3272@calimero.vinschen.de> (raw)
In-Reply-To: <CAF9ehCV3Mqp8Mns1QBeaQ-KbPdtQ4G_wpLK0sm9J46gZSU=-Mg@mail.gmail.com>

On Aug 31 10:10, Joel Sherrill wrote:
> Hi
> 
> I was porting some code from Linux to Cygwin and came across this. M_PI in
> math.h is defined by POSIX as part of XSI. It does not appear to be part of
> C99 or C++03.  I have this cut down to show the problem:
> 
> ==========================
> #include <math.h>
> 
> double pi = M_PI;
> ==========================
> 
> And this script to try various feature defines and compilers:
> 
> ===========================
> GCC=${GCC:-g++}
> 
> ${GCC} -c m.c
> ${GCC} -D_XOPEN_SOURCE=700 -c m.c
> ${GCC} -D_POSIX_C_SOURCE=200809L -c m.c
> ${GCC} -D_XOPEN_SOURCE=700 -c -D_POSIX_C_SOURCE=200809L -c m.c
> ===========================
> 
> All of those compiler invocations work on Linux but the third one does not
> work on Cygwin or RTEMS which use newlib.
> 
> Is the proper thing to do to add  -D_XOPEN_SOURCE=700 when compiling this
> program?
> 
> Just curious if Linux is defining _XOPEN_SOURCE by default and newlib
> doesn't.

In glibc's math.h, M_PI is guarded with

  #if defined __USE_MISC || defined __USE_XOPEN

In newlib, it's guarded with

  #if __BSD_VISIBLE || __XSI_VISIBLE

Note that this is identical to the guards on at least FreeBSD.

In both cases, newlib as well as glibc, "MISC" is defined by default,
but "BSD" isn't.  That's why your 3rd invocation fails on BSDs and
newlib/Cygwin, but not on Linux.

> Not sure what's the right answer. So asking.

Corinna


  reply	other threads:[~2020-08-31 15:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 15:10 Joel Sherrill
2020-08-31 15:27 ` Corinna Vinschen [this message]
2020-08-31 15:29   ` Corinna Vinschen
2020-08-31 15:50     ` Joel Sherrill
2020-08-31 20:04       ` Corinna Vinschen
2020-08-31 21:19         ` Joel Sherrill
2020-09-01  2:04           ` Yaakov Selkowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200831152715.GC3272@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).