From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 4C788384C005 for ; Mon, 31 Aug 2020 15:50:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4C788384C005 Received: by mail-ej1-x636.google.com with SMTP id e23so3671755eja.3 for ; Mon, 31 Aug 2020 08:50:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GVyt64DXUcTvJ6LvM5/HcQpbHX/TMd7RL38gcVktWsI=; b=dmRsNSy+tviHXEWnWVYAt4jYTh7H4Qnj4EcP3IsWlF9eGJaF/8jFHTZG72k2zT7Zi2 BBdE1yyUOKIkjZMprBP0dGGSBBuLxlEAaeOgwuDPLsoLNfKCViAUdavNT5SRpFCrWEpk YF/e9HsQm28AtycXGNt1FdLhHZEckwuyqH9aqvKusnHSCIhwZXV+CFsVgMro23jZ1RLV 8+mRdIoiJDlPC3GmgC3ZXwFsvRxJgRuNgu2WGa3MiRQbqpJo9jElwLlAXds5scuof6SY 3Q7QJpgRzySQI8zWnGA4F13RbNX8esj6vMTT6wMwKMP93U7UresDOWO3BGnUQOqq4AoY uk3A== X-Gm-Message-State: AOAM532AL3xWzXtW7/YWD+TEcMRIuJ6xHTfsEDUsznruRo9jhF3VL/Pe 7liIuoEoTIcncmGFvK2u5shX++JjMEPpQYfzGaxh/ddQVc/oJQ== X-Google-Smtp-Source: ABdhPJxDyh6Jd6xTjQ2oL77JzAaNI50MjDMEN6yCDuvnOzZAo/9yRJn/Nuk0YOznmLJiXJD647fAyEOmkIRnXVuiTFA= X-Received: by 2002:a17:907:9c3:: with SMTP id bx3mr1729263ejc.164.1598889016857; Mon, 31 Aug 2020 08:50:16 -0700 (PDT) MIME-Version: 1.0 References: <20200831152715.GC3272@calimero.vinschen.de> <20200831152959.GD3272@calimero.vinschen.de> In-Reply-To: <20200831152959.GD3272@calimero.vinschen.de> From: Joel Sherrill Date: Mon, 31 Aug 2020 10:50:04 -0500 Message-ID: Subject: Re: Feature Conditional for M_PI To: Newlib X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Aug 2020 15:50:20 -0000 On Mon, Aug 31, 2020 at 10:30 AM Corinna Vinschen via Newlib < newlib@sourceware.org> wrote: > On Aug 31 17:27, Corinna Vinschen via Newlib wrote: > > 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 > > > > > > 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. > Thanks for poking at the BSDs. I went and tried that also. > > Huh, wait! I bet this does *not* fail on BSD because BSD very likely > defines __BSD_VISIBLE by default. > The third case fails on FreeBSD 12 as well. > > We could move the math.h constants to __MISC_VISIBLE || __XSI_VISIBLE, > perhaps that makes more sense for us? > https://github.com/freebsd/freebsd/blob/master/lib/msun/src/math.h#L143 has this: #if __BSD_VISIBLE || __XSI_VISIBLE which matches your expectations on their wrapper but not the outcome. I guess they don't define __BSD_VISIBLE by default. If we want newlib to follow glibc, then this should change to MISC but I certainly would want to hear from some of the standards folks who are on this list. :) --joel > > > Corinna > >