From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6639 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 2/4] cimag and friends shouldn't return an lvalue Date: Tue, 2 Dec 2014 12:58:26 -0500 Message-ID: <20141202175826.GC29621@brightrain.aerifal.cx> References: <1416926859.16006.924.camel@eris.loria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1417543128 21463 80.91.229.3 (2 Dec 2014 17:58:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Dec 2014 17:58:48 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6652-gllmg-musl=m.gmane.org@lists.openwall.com Tue Dec 02 18:58:41 2014 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Xvrii-0007X6-6W for gllmg-musl@m.gmane.org; Tue, 02 Dec 2014 18:58:40 +0100 Original-Received: (qmail 3561 invoked by uid 550); 2 Dec 2014 17:58:39 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3553 invoked from network); 2 Dec 2014 17:58:38 -0000 Content-Disposition: inline In-Reply-To: <1416926859.16006.924.camel@eris.loria.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:6639 Archived-At: On Tue, Nov 25, 2014 at 03:49:55PM +0100, Jens Gustedt wrote: > This is nothing imperative, but is a bit more user friendly, because it > should error out in situations that a user of these macros can't expect > to work. > > If __GNU__ is detected, this uses the "__imag__" extension of gcc and > friends. This should be the less costly solution. It should not create a > temporary object, even in absence of optimization. This extension is > arround in all versions of gcc that provide complex arithmetic. > --- > include/complex.h | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/include/complex.h b/include/complex.h > index 3e14e04..be5bd7e 100644 > --- a/include/complex.h > +++ b/include/complex.h > @@ -101,8 +101,13 @@ double creal(double complex); > float crealf(float complex); > long double creall(long double complex); > > +#ifdef __GNUC__ > +#define __CIMAG(x, t) \ > + (__extension__ __imag__ (_Complex t)(x)) > +#else > #define __CIMAG(x, t) \ > - ((union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) > + (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) > +#endif Short of a good reason to need the GNU-specific version (like subtle non-conformance, performance issues, or other problems in the portable version), it's generally preferred in musl not to have multiple versions of the same code where one would go largely untested. But making it a non-lvalue seems like a good idea just to catch bugs. Rich