From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6622 Path: news.gmane.org!not-for-mail From: Jens Gustedt Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/4] cimag and friends shouldn't return an lvalue Date: Tue, 25 Nov 2014 15:49:55 +0100 Message-ID: <1416926859.16006.924.camel@eris.loria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1416927006 1299 80.91.229.3 (25 Nov 2014 14:50:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Nov 2014 14:50:06 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6635-gllmg-musl=m.gmane.org@lists.openwall.com Tue Nov 25 15:50:00 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 1XtHRF-0005Bc-Em for gllmg-musl@m.gmane.org; Tue, 25 Nov 2014 15:49:57 +0100 Original-Received: (qmail 3079 invoked by uid 550); 25 Nov 2014 14:49:56 -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 2047 invoked from network); 25 Nov 2014 14:49:56 -0000 X-IronPort-AV: E=Sophos;i="5.07,455,1413237600"; d="scan'208";a="109493365" Resent-From: Jens Gustedt Resent-To: musl@lists.openwall.com X-Mailer: Evolution 3.4.4-3 Xref: news.gmane.org gmane.linux.lib.musl.general:6622 Archived-At: 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 #define creal(x) ((double)(x)) #define crealf(x) ((float)(x)) -- 1.9.1