From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id BFFFB386EC49 for ; Mon, 31 Aug 2020 15:30:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BFFFB386EC49 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-m2-3WJK2O--b3ZEavIEEBg-1; Mon, 31 Aug 2020 11:30:02 -0400 X-MC-Unique: m2-3WJK2O--b3ZEavIEEBg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9AF1418BA2A7 for ; Mon, 31 Aug 2020 15:30:01 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-104.ams2.redhat.com [10.36.112.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 387266CE4F for ; Mon, 31 Aug 2020 15:30:01 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id B663BA80771; Mon, 31 Aug 2020 17:29:59 +0200 (CEST) Date: Mon, 31 Aug 2020 17:29:59 +0200 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: Feature Conditional for M_PI Message-ID: <20200831152959.GD3272@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20200831152715.GC3272@calimero.vinschen.de> MIME-Version: 1.0 In-Reply-To: <20200831152715.GC3272@calimero.vinschen.de> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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:30:08 -0000 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. Huh, wait! I bet this does *not* fail on BSD because BSD very likely defines __BSD_VISIBLE by default. We could move the math.h constants to __MISC_VISIBLE || __XSI_VISIBLE, perhaps that makes more sense for us? Corinna