Re: [RFC 3/3] kernel.h: use new typechecking macros in min()/max()and friends

From: Linus Torvalds
Date: Sat Apr 14 2012 - 17:18:11 EST


On Sat, Apr 14, 2012 at 3:14 PM, Sasha Levin <levinsasha928@xxxxxxxxx> wrote:
> Convert to using new typechecking macros in kernel.h. This prevents code
> duplication and makes the modified macros (easily) readable again.
>
>  #define min(x, y) ({                           \
> -       typeof(x) _min1 = (x);                  \
> -       typeof(y) _min2 = (y);                  \
> -       (void) (&_min1 == &_min2);              \
> -       _min1 < _min2 ? _min1 : _min2; })
> +       typecmp2((x), (y));                             \
> +       (x) < (y) ? (x) : (y); })

They may be readable, but they are total shit.

You now evaluate 'x' and 'y' multiple times, so if they are function
calls or contain other side effects (like "a++" etc), you get the
wrong result.

So no. Hell no.

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