[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] compiling problem



Evan Langlois <Evan@CoolRunningConcepts.com> writes:

> Anyway, its not MiNT's fault, although the #define for min() I normally
> see is something a bit simpler without all the assignment and local
> variable allocation, its still Sox's fault.

IMO, it would be better to write the macro in capitals, MIN(a,b)
instead, if it should be in the header files at all. 

> Perhaps the maintainer of
> mintlib, or someone wiser than I, can tell me what's wrong with this:
>
> #define min(a,b)	(((a) < (b)) ? (a) : (b))

Either a or b are evaluated twice here, which does not happen with the
current one. If you write code like:

 m = min(a++, b++);

you expect a and b to be increased with 1. One of them will be
increased with 2, if you use your simple macro.

Despite that, your version seems to be the more commonly used
anyway. You just have to know of the potential problem, when using
it.


Greetings,

Tomas