[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20100106150928.68819f8c.akpm@linux-foundation.org>
Date: Wed, 6 Jan 2010 15:09:28 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Roland Dreier <rdreier@...co.com>
Cc: linux-kernel@...r.kernel.org,
Bart Van Assche <bart.vanassche@...il.com>,
David Dillow <dave@...dillows.org>
Subject: Re: [PATCH] Add BUILD_BUG_ON_NOT_POWER_OF_2()
On Wed, 06 Jan 2010 15:02:40 -0800
Roland Dreier <rdreier@...co.com> wrote:
> Fair enough... here's your suggestion of BUILD_BUG_ON_NOT_POWER_OF_2().
> <linux/kernel.h> does seem to be going the way of a gazillion very
> specific helper macros, so I guess this fits right in.
>
> include/linux/kernel.h | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 3fc9f5a..a1b6652 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -734,6 +734,10 @@ struct sysinfo {
> /* Force a compilation error if condition is constant and true */
> #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
>
> +/* Force a compilation error if expression is not a power of 2 */
> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> + BUILD_BUG_ON(((n) != 0 && (((n) & ((n) - 1)) == 0)))
> +
> /* Force a compilation error if condition is true, but also produce a
> result (of value 0 and type size_t), so the expression can be used
> e.g. in a structure initializer (or where-ever else comma expressions
ok.. I'll give it a week or so for better ideas to turn up then I'll
send this Linuswards so that ongoing work can use it.
--
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