> From: Andrew Francis
>
> 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.
>

That's a good warning to consider, but the problem with using a function is
easily solved like this:
        y = somefunction();
        z = min(x, y);

The incrementing problem is unavoidable with a macro because the compiler
just does a text substitution.  So
        z = min(x++, y++);
becomes
        z = (((x++) < (y++)) ? (x++) : (y++))
and one of the two variables will be incremented twice.

Again, this is easily fixed.  Just don't use the increment operator so
casually.  e.g.,
        z = min(x, y);
        x++;
        y++;

I think most C programmers know this.


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to