From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Koning To: egcs@cygnus.com Subject: Re: min/max macros Date: Fri, 12 Dec 1997 07:51:00 -0000 Message-id: <9712121550.AA19616@kona.> References: <01BD0625.FDFCC640@bill.icdata.com> X-SW-Source: 1997-12/msg00733.html >>>>> "Bill" == Bill Ahlbrandt writes: Bill> I have noticed that these macros are not always available and Bill> not always in the same place. Specifically, with egcs, they Bill> seem to be in curses.h Bill> I "coded" my own and used them as follows: Bill> #define max(a,b) (((a) > (b)) ? (a) : (b)) #define min(a,b) Bill> (((a) < (b)) ? (a) : (b)) Bill> After discovering that max in particular was not yielding the Bill> desired results, I coded these macros as functions. All of my Bill> problems went away. It's always dangerous to create macros that use a macro argument more than once. You will get the wrong results if the macro is called with an actual argument that has side effects (e.g., max (i++, j++) ). Apart from that, functions have the benefit of type checking. For these reasons, I tend to use functions when I can. You can declare them "static inline" to get the benefits without any performance penalties. paul