From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751985Ab0HUSkV (ORCPT ); Sat, 21 Aug 2010 14:40:21 -0400 Received: from mail.openrapids.net ([64.15.138.104]:34119 "EHLO blackscsi.openrapids.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751173Ab0HUSkS (ORCPT ); Sat, 21 Aug 2010 14:40:18 -0400 Date: Sat, 21 Aug 2010 14:40:15 -0400 From: Mathieu Desnoyers To: Alexey Dobriyan , Jan Beulich , Roland Dreier Cc: LKML , ltt-dev@lists.casi.polymtl.ca, Linus Torvalds , Andrew Morton , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Frederic Weisbecker , Thomas Gleixner , Christoph Hellwig , Li Zefan , Lai Jiangshan , Johannes Berg , Masami Hiramatsu , Arnaldo Carvalho de Melo , Tom Zanussi , KOSAKI Motohiro , Andi Kleen , Alexander Shishkin , Russell King - ARM Linux , linux-arm-kernel@lists.infradead.org, Imre Deak , Jamie Lokier , "Kirill A. Shutemov" Subject: Re: [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Message-ID: <20100821184015.GA17805@Krystal> References: <20100821141750.770348530@efficios.com> <20100821142215.023431313@efficios.com> <20100821182623.GA9621@core2.telecom.by> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100821182623.GA9621@core2.telecom.by> X-Editor: vi X-Info: http://www.efficios.com X-Operating-System: Linux/2.6.26-2-686 (i686) X-Uptime: 14:36:49 up 210 days, 21:13, 4 users, load average: 0.20, 0.14, 0.10 User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Alexey Dobriyan (adobriyan@gmail.com) wrote: > On Sat, Aug 21, 2010 at 10:17:51AM -0400, Mathieu Desnoyers wrote: > > +/* Force a compilation error if condition is constant and not a power of 2 */ > > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \ > > + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) > > Sorry, this is tasteless macro. Let's look at the surrounding where I added this macro in kernel.h: /* Force a compilation error if condition is true */ #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) /* 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 a constant 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 aren't permitted). */ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) So I am guessing that you plan to rewrite all of these ? Or perharps you have other suggestions ? Commit cc8ef6eb21e964b1c5eb97b2d0e8ac9893e1bf86 introduced "BUILD_BUG_ON_NOT_POWER_OF_2()" btw. Thanks, Mathieu -- Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com