Mail Archives: djgpp/1996/10/23/10:39:05
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 -