delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/23/10:39:05

Date: Wed, 23 Oct 1996 16:10:57 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "John M. Aldrich" <fighteer AT cs DOT com>
Cc: dokk <dokk AT top DOT monad DOT net>, djgpp AT delorie DOT com
Subject: Re: Borland library macro equivalent?
In-Reply-To: <326C25F9.1FBB@cs.com>
Message-Id: <Pine.SUN.3.91.961023132054.7645C-100000@is>
Mime-Version: 1.0

On Mon, 21 Oct 1996, John M. Aldrich wrote:

> #define min(a,b)	((a) < (b) ? (a) : (b))
> #define max(a,b)	((a) > (b) ? (a) : (b))
> 
> Be warned that in using the above code, the expression that gets
> returned by the macro will be evaluated _twice_ by your program; i.e.,
> the following program fragment:

Ha!  That's GCC we are using, remember?  We don't need to suffer from no
steenking double-evaluating compilers anymore: 

	#define max(a,b) ({ typeof(a) _tmp_a = (a); \
			    typeof(b) _tmp_b = (b); \
			    (_tmp_a > _tmp_b) ? _tmp_a : _tmp_b; })

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019