public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: min/max macros
@ 1997-12-11 19:02 Mike Stump
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Stump @ 1997-12-11 19:02 UTC (permalink / raw)
  To: bahlbr, egcs

> Date: Thu, 11 Dec 1997 12:03:45 -0800
> From: dave madden <dhm@paradigm.webvision.com>

> min/max macros are not inherently bad, as long as you understand
> that they evaluate their arguments more than once.

Spraying a crowd with bullets from an automatic rife isn't bad, it's
only bad if people get hit...


Bad.  Period.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [EGCS] Re: min/max macros
  1997-12-11 13:43 ` Gerald Pfeifer
@ 1997-12-11 17:57 Marc Lehmann
  1997-12-11 19:51 ` Joe Buck
  -1 siblings, 1 reply; 7+ messages in thread
From: Marc Lehmann @ 1997-12-11 17:57 UTC (permalink / raw)
  To: egcs

> > #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.

so egcs isn't a decent compiler?

for example, the macro-max(2,3) will be evaluated at compile time,
while the function-max(2,3) won't...

this get's even worse on things like:

int mult(int a, int b) { return a*b; };

mult(a,3) will result in an "imul 3" on x86... definitely
slower than a lea, for example.

      -----==-                                              |
      ----==-- _                                            |
      ---==---(_)__  __ ____  __       Marc Lehmann       +--
      --==---/ / _ \/ // /\ \/ /       pcg@goof.com       |e|
      -=====/_/_//_/\_,_/ /_/\_\                          --+
    The choice of a GNU generation                        |
                                                          |

^ permalink raw reply	[flat|nested] 7+ messages in thread
* min/max macros
@ 1997-12-11  9:17 Bill Ahlbrandt
  1997-12-11 13:03 ` dave madden
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Bill Ahlbrandt @ 1997-12-11  9:17 UTC (permalink / raw)
  To: 'egcs@cygnus.com'

I have noticed that these macros are not always available and not always in the same place.

Specifically, with egcs, they seem to be in curses.h

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))

After discovering that max in particular was not yielding the desired results, I coded these macros as functions.  All of my problems went away.

Is it generally a bad plan to use macros like this?  Are there any known problems with egcs involving macros such as these?

Thanks in advance..

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-12-12 10:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-11 19:02 min/max macros Mike Stump
  -- strict thread matches above, loose matches on Subject: below --
1997-12-11 17:57 [EGCS] " Marc Lehmann
1997-12-11 19:51 ` Joe Buck
1997-12-12 10:18   ` Marc Lehmann
1997-12-11  9:17 Bill Ahlbrandt
1997-12-11 13:03 ` dave madden
1997-12-11 13:03 ` Michael A. Benzinger
1997-12-11 13:43 ` Gerald Pfeifer
1997-12-12  7:51 ` Paul Koning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).