Re: [IDEA+RFC] Possible solution for min()/max() war

From: Alexander Viro (viro@math.psu.edu)
Date: Fri Aug 24 2001 - 20:15:43 EST


On Fri, 24 Aug 2001, Brad Chapman wrote:

> OK. The existing API is wrong and the new min()/max() macros are the
> right way to properly compare values. However, we could always add a config
> option to enable a compatibility macro, which would use typeof() on one of the
> two variables and then call the real min()/max(). Something like this (just an
> example):
>
> #ifdef CONFIG_ALLOW_COMPAT_MINMAX
> #define proper_min(t, a, b) ((t)(a) < (t)(b) ? (a) : (b))
> #define proper_max(t, a, b) ((t)(a) > (t)(b) ? (a) : (b))
> #define min(a, b) proper_min(typeof(a), a, b)
> #define max(a, b) proper_max(typeof(a), a, b)

_THAT_ _IS_ _WRONG_. Who the fuck said that we always want type of _first_
argument? Mind you, IMNSHO Dave had been on a seriously bad trip when he
had added that "type" argument - separate names would be cleaner. And yes,
it'd be better in prepatch instead of 2.4.9-final.

However, no matter which variant you pick, old code with min/max
was broken. Unless you are carefully giving right types (preferanly -
with casts) it works only by accidents (if it works at all).

"Compatibility option" is exactly the worst thing in such cases.
It's either changing the whole codebase or not bothering at all.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Aug 31 2001 - 21:00:16 EST