"Andrew Francis" <[EMAIL PROTECTED]> wrote in message
news:55429@palm-dev-forum...
>
> > ----- Original Message -----
> > From: "Rhoda BEROL" <[EMAIL PROTECTED]>
> > > What is the name of the fonction which return the minimum between
2
> > numbers
> > > (version SDK 4.0)?
> >
> > It's called:
> >
> > #define MIN(x,y) ((x)<(y)?(x):(y))
>
> Just be warned that you should only use static values with this macro.
> For instance, MIN(x, somefunction()) would be a bad idea - because if
> somefunction() is lower it would be called twice! And if you had
> min(x++, y++) then the smallest value would increase by two.
>
> If you want to avoid this then you can't use a macro... you'll need a
> function.
In C++, a good minimum function would be
template <typename T>
inline T
min(const T& a, const T& b)
{
return (a < b) ? a : b;
}
which would make an inline minimum statement with only one evaluation
for a and b, plus a single copy operation for the return. Plus, its
typesafe, only comparing items of the same type.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/