Mail Archives: djgpp/1996/10/22/19:23:11
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 -