From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755691AbbLDI74 (ORCPT ); Fri, 4 Dec 2015 03:59:56 -0500 Received: from mail-lf0-f54.google.com ([209.85.215.54]:36420 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755287AbbLDI7y convert rfc822-to-8bit (ORCPT ); Fri, 4 Dec 2015 03:59:54 -0500 From: Rasmus Villemoes To: Joe Perches Cc: Andrew Morton , Andy Shevchenko , Kees Cook , Martin Kletzander , Andy Shevchenko , Maurizio Lombardi , Tejun Heo , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 04/14] lib/vsprintf.c: expand field_width to 24 bits Organization: D03 References: <1449175873-1780-1-git-send-email-linux@rasmusvillemoes.dk> <1449175873-1780-5-git-send-email-linux@rasmusvillemoes.dk> <1449176047.17296.4.camel@perches.com> <1449178138.15393.161.camel@linux.intel.com> <20151203153407.85761faeab07e7c2fed84e81@linux-foundation.org> <1449187382.17296.16.camel@perches.com> X-Hashcash: 1:20:151204:tj@kernel.org::+kcuQhMstE82rU17:000010Wc X-Hashcash: 1:20:151204:linux-kernel@vger.kernel.org::tTcRObnhs5syH1X0:0000000000000000000000000000000000ulN X-Hashcash: 1:20:151204:andy.shevchenko@gmail.com::hgunBveJ47y4/1ev:0000000000000000000000000000000000002Vt2 X-Hashcash: 1:20:151204:joe@perches.com::/Hhd4L2991p8vlLJ:003tKr X-Hashcash: 1:20:151204:mkletzan@redhat.com::goEwCN5o+jdD85wG:0000000000000000000000000000000000000000003TYI X-Hashcash: 1:20:151204:keescook@chromium.org::ViNiSZxvl3qJqYSw:000000000000000000000000000000000000000049gi X-Hashcash: 1:20:151204:andriy.shevchenko@linux.intel.com::uf3JDYgpho/Eql41:00000000000000000000000000009Qp1 X-Hashcash: 1:20:151204:akpm@linux-foundation.org::J9pnGmZeHxMo46nl:0000000000000000000000000000000000009nmH X-Hashcash: 1:20:151204:mlombard@redhat.com::1J6SdAfU/mtjLI9t:000000000000000000000000000000000000000000HnIx Date: Fri, 04 Dec 2015 09:59:50 +0100 In-Reply-To: <1449187382.17296.16.camel@perches.com> (Joe Perches's message of "Thu, 03 Dec 2015 16:03:02 -0800") Message-ID: <87twny612x.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 04 2015, Joe Perches wrote: > On Thu, 2015-12-03 at 15:34 -0800, Andrew Morton wrote: >> I've been fiddling with a BUILD_BUG_ON which works outside functions >> using gcc's __COUNTER__ - something like >> >> #define BBO(expr) typedef char __bbo##__COUNTER__[1-2*(!!expr)] > > nit:  you need another parenthesis around expr > >> BBO(1 == 1); >> BBO(2 == 2); >> >> but that comes out as >> >> typedef char __bbo__COUNTER__[1-2*(!!1 == 1)]; >> typedef char __bbo__COUNTER__[1-2*(!!2 == 2)]; >> >> instead of >> >> typedef char __bbo0[1-2*(!!1 == 1)]; >> typedef char __bbo1[1-2*(!!2 == 2)]; >> >> There's some trick here but I've forgotten what it is. > > I believe it's something like: > > #define __stringify_2(a, b) a##b > #define __stringify2(a, b) __stringify_2(a, b) > > #define BBO(expr) typedef char __stringify2(bbo, __COUNTER__)[1 - 2*(!!(expr))] Let's at least not reinvent two wheels. __UNIQUE_ID exists and does the gluing (which we have __PASTE for, not stringify) etc., and uses __LINE__ as a poor man's fallback for compilers without __COUNTER__ (gcc < 4.3). But I don't see why we even need the unique identifier. What's wrong with 'extern char blabla[1 - 2*(!!(expr))]'? blabla can be declared multiple times without problems - and when it fails, we either get a 'negative size' error or at least some complaint about conflicting declarations. Maybe stick a __always_unused in to prevent gcc from complaining if this declaration is inside a function. Rasmus