[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+55aFxDXPUCvP4CUWcz7aCNPkgTm1whDXh5GxJd4v-DcGPX2g@mail.gmail.com>
Date:	Sat, 14 Apr 2012 14:17:53 -0700
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	Sasha Levin <levinsasha928@...il.com>
Cc:	akpm@...ux-foundation.org, peterz@...radead.org, mingo@...e.hu,
	hpa@...or.com, tglx@...utronix.de,
	srivatsa.bhat@...ux.vnet.ibm.com, linux-kernel@...r.kernel.org
Subject: Re: [RFC 3/3] kernel.h: use new typechecking macros in min()/max()
 and friends
On Sat, Apr 14, 2012 at 3:14 PM, Sasha Levin <levinsasha928@...il.com> 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Powered by blists - more mailing lists