www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/22/19:23:11

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Borland library macro equivalent?
Date: Mon, 21 Oct 1996 18:40:09 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 43
Message-ID: <326C25F9.1FBB@cs.com>
References: <199610210655 DOT CAA09066 AT top DOT monad DOT net>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: dokk <dokk AT top DOT monad DOT net>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

dokk wrote:
> 
> Hi all,
> 
> Can someone help me out here? I'm converting a simple piece of code from
> Borland C++ 4.0 compatible C source, and I need a DJGPP V2 equivalent of the
> Borland library macros "min(a,b)" and "max(a,b)". I have absolutely no
> experience of Borland, so any assistance here would really help me out.

I am assuming here that the macros simply evaluate the smallest and/or
largest value out of two?  Then the equivalent (in any compiler) would
be:

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

    int a = 4;
    int b = 3;

    printf( "%d", max(a++, b++) );

will produce '6' as output, not '5', because the printf line expands to:

    printf( "%d", ((a++) > (b++) ? (a++) : (b++)) );

Similarly,

    result = max( func1( a, b ), func2( a, b ) );

will cause either func1() or func2() to be called twice.

Good luck!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |        fighteer AT cs DOT com          |
| Proud owner of what might one   |   http://www.cs.com/fighteer    |
| day be a spectacular MUD...     | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019