Date: Wed, 23 Oct 1996 16:10:57 +0200 (IST) From: Eli Zaretskii To: "John M. Aldrich" Cc: dokk , djgpp AT delorie DOT com Subject: Re: Borland library macro equivalent? In-Reply-To: <326C25F9.1FBB@cs.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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; })