From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbbJGIPd (ORCPT ); Wed, 7 Oct 2015 04:15:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:59560 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750947AbbJGIP3 (ORCPT ); Wed, 7 Oct 2015 04:15:29 -0400 Subject: Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic To: Rasmus Villemoes References: <5613F3DE.4010406@suse.cz> <1444165543-2209-1-git-send-email-linux@rasmusvillemoes.dk> Cc: Paul Gortmaker , Jiri Slaby , Ingo Molnar , Andrew Morton , Thomas Gleixner , "H. Peter Anvin" , linux-kernel@vger.kernel.org From: Michal Marek Message-ID: <5614D49F.8070006@suse.cz> Date: Wed, 7 Oct 2015 10:15:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1444165543-2209-1-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2015-10-06 23:05, Rasmus Villemoes wrote: > It's not hard to generalize the macro magic used to build the > IS_ENABLED macro and friends to produce a few other potentially useful > macros: > > CHOOSE_EXPR(CONFIG_FOO, expr): if CONFIG_FOO is set expands to > expr, otherwise expands to nothing. > > CHOOSE_EXPR(CONFIG_FOO, expr1, expr2): if CONFIG_FOO is set, > expands to expr1, otherwise expands to expr2. FWIW, I agree with Ingo that the CHOOSE_EXPR name is not really obvious. IF_CONFIG is a better alternative IMO, since the average programmer probably does not know __builtin_choose_expr() to see the analogy. > Similarly, we can define helpers for conditional struct members and > their associated initializers. It would probably take some time to get > used to reading, to pick another random example, > > struct task_struct { > ... > COND_DECLARATION(CONFIG_KASAN, unsigned int kasan_depth) > ... > } While the C standard syntax requires struct-declaration to actually declare a member, the compiler will happily ignore the extra semicolon if you write truct task_struct { ... CHOOSE_EXPR(CONFIG_KASAN, unsigned int kasan_depth); ... } So I think that the COND_DECLARATION macro is not necessary. > #define INIT_KASAN(tsk) COND_INITIALIZER(CONFIG_KASAN, .kasan_depth = 1) COND_INITIALIZER on the other hand is useful (CHOOSE_EXPR(CONFIG_KASAN, .kasan_depth = 1 _COMMA) does does not work, unfortunately). > [and I'm certainly not proposing any mass conversion], but I think it > might be nice to avoid lots of short #ifdef/#else/#endif sections. It should be accompanied by a patch to scripts/tags.sh teaching ctags/etags about the new macros. Michal