From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gerald Pfeifer To: egcs@cygnus.com Cc: Bill Ahlbrandt Subject: Re: min/max macros Date: Thu, 11 Dec 1997 13:43:00 -0000 Message-id: References: <01BD0625.FDFCC640@bill.icdata.com> X-SW-Source: 1997-12/msg00675.html On Thu, 11 Dec 1997, Bill Ahlbrandt wrote: > I "coded" my own and used them as follows: > > #define max(a,b) (((a) > (b)) ? (a) : (b)) > #define min(a,b) (((a) < (b)) ? (a) : (b)) That is a big no-no: Absolutely no performance benefits with any decent compiler but nasty side effects. > After discovering that max in particular was not yielding the desired > results [...] You didn't happen to use "max(i++,prev_max)" or similar, did you? For that expands to (((i++) > (prev_max)) ? (i++) : (prev_max)) which may increment i twice as an -- usually unintended -- side-effect. Hope this helps, Gerald -- Gerald Pfeifer (Jerry) Vienna University of Technology pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/