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

Christopher Friesen (cfriesen@nortelnetworks.com)
Wed, 29 Aug 2001 16:07:10 -0400


Herbert Rosmanith wrote:

> #define type_min(type,x,y) \
> ({ type __x = (x), __y = (y); __x < __y ? __x: __y; })
> #define type_max(type,x,y) \
> ({ type __x = (x), __y = (y); __x > __y ? __x: __y; })
>
> #define min(x,y) type_min(typeof(x),x,y)
> #define max(x,y) type_max(typeof(x),x,y)
>
> no _implicit_ cast and ...
>
> > One of the arguments gets changed invisibly, and that is what kernel
> > developers are so upset about. You don't really know which one without
> > thinking hard about it, and that is a source of many hard-to-find bugs.
>
> ... joy, we would even know which one.

I think this makes a lot of sense. The explicit version could be preferred, but
for the implicit version we at least know that what type will be used for it and
it won't immediately break things that are still using the old-style min/max.

-- 
Chris Friesen                    | MailStop: 043/33/F10  
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com
-
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/