This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: min/max macros
- To: egcs at cygnus dot com
- Subject: Re: min/max macros
- From: Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>
- Date: Thu, 11 Dec 1997 22:43:02 +0100 (MET)
- cc: Bill Ahlbrandt <bahlbr at icdata dot com>
- Reply-To: egcs at cygnus dot com
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/