From owner-freebsd-standards Mon Feb 10 5:18:12 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5049237B401 for ; Mon, 10 Feb 2003 05:18:11 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F50443F75 for ; Mon, 10 Feb 2003 05:18:09 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id AAA06856; Tue, 11 Feb 2003 00:17:42 +1100 Date: Tue, 11 Feb 2003 00:17:44 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: David Schultz Cc: Dag-Erling Smorgrav , Lukas Ertl , Subject: Re: C99 floating point macros In-Reply-To: <20030210020259.GA4103@HAL9000.homeunix.com> Message-ID: <20030210234147.B890-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, 9 Feb 2003, David Schultz wrote: > Thus spake Dag-Erling Smorgrav : > > David Schultz writes: > > > Hmm...why not just use some macros, like this? > > > > Macros behave strangely when invoked with arguments which have side > > effects. This would be a programmer error, since these interfaces are specified to be macros. > Doh! I should have seen that. I'll wrap them in a do...while(0) > with a local variable. Thanks for the catch! I thought that you saw it. Implementing these interfaces using local a local variable would be very messy and/or unportable. To begin with, do...while(0) doesn't work because it cannot return a value. A not very messy but very unportable version could use gcc statement-expressions and __typeof. Portable versions seem to require combinatorial explosion (3 * 3 cases): #define isgreater(x, y) ( \ sizeof(x) == 4 && sizeof(y) == 4 ? isgreaterff((x), (y)) : \ sizeof(x) == 4 && sizeof(y) == 8 ? isgreaterfd((x), (y)) : \ sizeof(x) == 4 && sizeof(y) > 8 ? isgreaterfld((x), (y)) : \ sizeof(x) == 8 && sizeof(y) == 4 ? isgreaterdf((x), (y)) : \ sizeof(x) == 8 && sizeof(y) == 8 ? isgreaterdd((x), (y)) : \ sizeof(x) == 8 && sizeof(y) > 8 ? isgreaterdld((x), (y)) : \ sizeof(x) > 8 && sizeof(y) == 4 ? isgreaterldf((x), (y)) : \ sizeof(x) > 8 && sizeof(y) == 8 ? isgreaterldd((x), (y)) : \ sizeof(x) > 8 && sizeof(y) > 8 ? isgreaterldld((x), (y)) : \ (abort(), 0)) /* * The final step seems to require functions to avoid side effects * (unless we use expression-statements). The above just avoids using * __typeof (using a not completely portable sizeof() hack). */ int isgreaterff(float x, float y); ... I think your simpler macros are better. Why protect the programmer more than for getc_unlocked (was: getc())? Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message